What SqlExceptions can be thrown

G

Guest

to my application?

In my web service, I'm using the Sql Data provider for .NET. I put the code
that sets up parameters, my call to Connection.Open(), and to
Command.ExecuteNonQuery() in a try block, then catch SqlException.

The problem is, I have been unable to determine what SqlExceptions might be
thrown to my app, and what they might mean. Specifically, I need to know
whether or not the stored procedure I just ran executed successfully. Is
there any place I can look this up?

Thanks in advance.
 
N

Nicholas Paldino [.NET/C# MVP]

Diane,

If all you need to know is if the stored procedure you ran completed
successfully, then all you have to do is determine whether or not there was
an exception, if not, then the command succeeded.

As for what SqlExceptions might be thrown, the SqlException class will
have more information based on the specific errors that SQL server returns.
In the end though, it's that one exception that is thrown, with additional
information.

Is there a particular error that you are trying to catch from SQL
server? If so check the Errors property on the exception instance and then
look at the Number property of the individual errors, checking against the
specific errors you are looking for.

Hope this helps.
 
G

Guest

Thanks. So, it would be safe to assume that for some reason or another that
my stored procedure failed, and I could just log it and deal with the
failure. There is no case where a SqlException exception would be
informational, but not indicate a complete failure?

Diane

Nicholas Paldino said:
Diane,

If all you need to know is if the stored procedure you ran completed
successfully, then all you have to do is determine whether or not there was
an exception, if not, then the command succeeded.

As for what SqlExceptions might be thrown, the SqlException class will
have more information based on the specific errors that SQL server returns.
In the end though, it's that one exception that is thrown, with additional
information.

Is there a particular error that you are trying to catch from SQL
server? If so check the Errors property on the exception instance and then
look at the Number property of the individual errors, checking against the
specific errors you are looking for.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)


Diane Droubay said:
to my application?

In my web service, I'm using the Sql Data provider for .NET. I put the
code
that sets up parameters, my call to Connection.Open(), and to
Command.ExecuteNonQuery() in a try block, then catch SqlException.

The problem is, I have been unable to determine what SqlExceptions might
be
thrown to my app, and what they might mean. Specifically, I need to know
whether or not the stored procedure I just ran executed successfully. Is
there any place I can look this up?

Thanks in advance.
 
J

Jon Skeet [C# MVP]

<"=?Utf-8?B?RGlhbmUgRHJvdWJheQ==?=" <Diane
Thanks. So, it would be safe to assume that for some reason or another that
my stored procedure failed, and I could just log it and deal with the
failure. There is no case where a SqlException exception would be
informational, but not indicate a complete failure?

That depends. Your stored procedure could have detected the failure
itself and corrected the problem, potentially. Unfortunately, with SQL
Server 2000 I don't believe it could then stop the exception from
bubbling up to your .NET code.

If you end up in this situation, you could make the stored procedure
have an out parameter which indicated what the SP thought in terms of
success/failure.
 
G

Guest

This helps. Thanks!

Jon Skeet said:
<"=?Utf-8?B?RGlhbmUgRHJvdWJheQ==?=" <Diane


That depends. Your stored procedure could have detected the failure
itself and corrected the problem, potentially. Unfortunately, with SQL
Server 2000 I don't believe it could then stop the exception from
bubbling up to your .NET code.

If you end up in this situation, you could make the stored procedure
have an out parameter which indicated what the SP thought in terms of
success/failure.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top