|
try / finally Posted: 04 Dec 2009 07:23 AM |
Hi,
I'm currently evaluating this product and my first impressions of it are very good. When looking at the generated code however, there is something I'm wondering about.
The methods generated in the DataProvider look like this
public Boolean UpdateT (String name, String name_Original, Int32 id,DbTransaction tran)
{
Boolean success;
DbConnection sqlcon = InitializeConnection(tran);
[Some stuff going on here, filling parameter values etc.]
int rowsAffected = ExecuteNonQuery(sqlcon, tran, "[dbo][oSP_Update_T]", sps);
success = ( rowsAffected > 0 );
FinalizeConnection(sqlcon, tran);
return success;
}
When writing this code myself, I'd use a try/finally section and it would become something like this:
public Boolean UpdateT (String name, String name_Original, Int32 id,DbTransaction tran)
{
Boolean success = false;
DbConnection sqlcon = InitializeConnection(tran);
try
{
[Some stuff going on here, filling parameter values etc.]
int rowsAffected = ExecuteNonQuery(sqlcon, tran, "[dbo][oSP_Update_T]", sps);
success = ( rowsAffected > 0 );
}
finally
{
FinalizeConnection(sqlcon, tran);
}
return success;
}
I know that the methods in the CommonDataProviderBase (ExecuteNonQuery in this case) contain a try/finally section that would call 'FinalizeConnection' on a failure, but still, when something goes wrong in the part [Some stuff going on here,..] (Ok, when looking at the code there a failure is very unlikely, but you never know..) the FinalizeConnection will never be called.
So, is there is a reason you solved it this way, am I overlooking something??
|
|
|
 |
|
Bogdan
|
 |
 |
| Joined: 01 Feb 2008 |
| Total Posts: 17 |
| |
|
Re: try / finally Posted: 05 Dec 2009 08:57 AM |
We are glad that you like the product. We are going to have our engineers to look at your
question/suggestion and get back to you.
Thanks |
|
|
 |
|
Arinze
|
 |
 |
| Joined: 02 Feb 2008 |
| Total Posts: 105 |
| |
|
Re: try / finally Posted: 08 Dec 2009 01:17 PM |
You make a valid point.
Our initial thought was that the errors should occur when we execute against the database.
But, there could be errors preceeding that (very unlikely).
We could also move the 'InitializeConnection' call closer to the 'Execute' call.
Food for thought (and change) |
OxyGen Code Generator, the Architected RAD Tool for .NET |
|
 |
|