Using transactions
hi,
i using c#.net 2005, sql server 2000.
i have few questions ask. firstly, can me telling difference between code below , same code comments removed:
string localquery = "select bla bla";
sqldataadapter _sda;
datatable _dt;
sqlcommand _cmd;
bool iserrcatched = false;
exception exctothrow = new exception();
using (sqlconnection _cn = newconnection) // newconnection returns static sqlconnection object
{
_cn.open();
_cmd = new sqlcommand(localquery, _cn);
//sqltransaction mytrans;
//mytrans = _cn.begintransaction();
//_cmd.transaction = mytrans;
_dt = new datatable();
_sda = new sqldataadapter(_cmd);
try
{
_sda.fill(_dt);
_sda.dispose();
//mytrans.commit();
}
catch (exception exc)
{
//try { mytrans.rollback(); } catch {}
iserrcatched = true;
exctothrow = exc;
}
finally
{
_cn.close();
}
_cmd.dispose();
}
_cmd = null;
if (iserrcatched)
throw exctothrow;
return _dt;
my first question: can there performance loss if uncomment lines transaction usage? mean, when start more timeouts.
my problem goes on. when comment lines , run stress tool, getting "column x not belong table y" errors. if lines not commented not getting error, timeout errors frequently. so, second question: there wrong in query or there bad coding practice following? offer better , more robust sample code block?
by way, connection pooling on. , these errors observed under high loads.
thanks everybody.
i using c#.net 2005, sql server 2000.
i have few questions ask. firstly, can me telling difference between code below , same code comments removed:
string localquery = "select bla bla";
sqldataadapter _sda;
datatable _dt;
sqlcommand _cmd;
bool iserrcatched = false;
exception exctothrow = new exception();
using (sqlconnection _cn = newconnection) // newconnection returns static sqlconnection object
{
_cn.open();
_cmd = new sqlcommand(localquery, _cn);
//sqltransaction mytrans;
//mytrans = _cn.begintransaction();
//_cmd.transaction = mytrans;
_dt = new datatable();
_sda = new sqldataadapter(_cmd);
try
{
_sda.fill(_dt);
_sda.dispose();
//mytrans.commit();
}
catch (exception exc)
{
//try { mytrans.rollback(); } catch {}
iserrcatched = true;
exctothrow = exc;
}
finally
{
_cn.close();
}
_cmd.dispose();
}
_cmd = null;
if (iserrcatched)
throw exctothrow;
return _dt;
my first question: can there performance loss if uncomment lines transaction usage? mean, when start more timeouts.
my problem goes on. when comment lines , run stress tool, getting "column x not belong table y" errors. if lines not commented not getting error, timeout errors frequently. so, second question: there wrong in query or there bad coding practice following? offer better , more robust sample code block?
by way, connection pooling on. , these errors observed under high loads.
thanks everybody.
could run query(select) in query analyser , see result
madhu
SQL Server > .NET Framework inside SQL Server
Comments
Post a Comment