By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,985 Members | 1,161 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,985 IT Pros & Developers. It's quick & easy.

try and catch in a Transaction

P: n/a
Hi,

Would someone tell me why errors happen in TestCommand.ExecuteNonQuery and
the application just hang in there, it won't go to the catch. Why?
Thanks for help.
Jason

try
{
TestCommand[i].Transaction=myTrans;
TestCommand[i].ExecuteNonQuery();
}
catch (SqlException EQry)
{
MessageBox.Show(String.Format("An exception occurred" +
" : {0}. Please contact your system administrator.", EQry.Message));
}
May 15 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi Jason,

Currently, the catch operator catches exceptions of type
System.Data.SqlClient.SqlException that occur in the
SqlCommand.ExecuteNonQuery() call [1]. Most likely the exception that is
thrown (and unhandled) is not of the aforementioned type.

You can append another catch statement for handling exceptions of type
System.InvalidOperationException and/or System.Exception, because they can be
thrown in certain circumstances, too.

[1] SqlCommand Documentation:
http://msdn2.microsoft.com/en-us/library/z4956bkc.aspx

--
Stanimir Stoyanov
www.stoyanoff.info
"Jason Huang" wrote:
Hi,

Would someone tell me why errors happen in TestCommand.ExecuteNonQuery and
the application just hang in there, it won't go to the catch. Why?
Thanks for help.
Jason

try
{
TestCommand[i].Transaction=myTrans;
TestCommand[i].ExecuteNonQuery();
}
catch (SqlException EQry)
{
MessageBox.Show(String.Format("An exception occurred" +
" : {0}. Please contact your system administrator.", EQry.Message));
}

May 15 '06 #2

P: n/a
Thanks Stanimir.
I now also have the System.InvalidOperationException and System.Exception on
the catch,
and it is System.FormaException shows up on the MessageBox.
But is it possible to know what data/field brings out the error?
Thanks for help.
Jason

Hi Jason,

Currently, the catch operator catches exceptions of type
System.Data.SqlClient.SqlException that occur in the
SqlCommand.ExecuteNonQuery() call [1]. Most likely the exception that is
thrown (and unhandled) is not of the aforementioned type.

You can append another catch statement for handling exceptions of type
System.InvalidOperationException and/or System.Exception, because they can
be
thrown in certain circumstances, too.

[1] SqlCommand Documentation:
http://msdn2.microsoft.com/en-us/library/z4956bkc.aspx

--
Stanimir Stoyanov
www.stoyanoff.info
"Jason Huang" wrote:
Hi,

Would someone tell me why errors happen in TestCommand.ExecuteNonQuery
and
the application just hang in there, it won't go to the catch. Why?
Thanks for help.
Jason

try
{
TestCommand[i].Transaction=myTrans;
TestCommand[i].ExecuteNonQuery();
}
catch (SqlException EQry)
{
MessageBox.Show(String.Format("An exception occurred" +
" : {0}. Please contact your system administrator.",
EQry.Message));
}

May 16 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.