Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / ADO.NET / March 2008

Tip: Looking for answers? Try searching our database.

Get error raised from sql command?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Smokey Grindel - 06 Mar 2008 00:55 GMT
Is there a way to get an error that is raised from a sql server stored
procedure when executed from a sqlcommand object? thanks!
Misbah Arefin - 06 Mar 2008 07:03 GMT
try RAISEERROR
http://msdn2.microsoft.com/en-us/library/ms177497.aspx

Signature

Misbah Arefin
https://mcp.support.microsoft.com/profile/MISBAH.AREFIN
http://www.linkedin.com/in/misbaharefin

> Is there a way to get an error that is raised from a sql server stored
> procedure when executed from a sqlcommand object? thanks!
Smokey Grindel - 06 Mar 2008 12:39 GMT
I think you misunderstood me... I already am raising errors in the stored
proc's... I want to know how I can find out what the error was when I ran it
inside of ADO.NET so I can respond to the error in my program

> try RAISEERROR
> http://msdn2.microsoft.com/en-us/library/ms177497.aspx
>
>> Is there a way to get an error that is raised from a sql server stored
>> procedure when executed from a sqlcommand object? thanks!
Mufaka - 06 Mar 2008 17:27 GMT
> I think you misunderstood me... I already am raising errors in the stored
> proc's... I want to know how I can find out what the error was when I ran it
[quoted text clipped - 5 lines]
>>> Is there a way to get an error that is raised from a sql server stored
>>> procedure when executed from a sqlcommand object? thanks!

What severity are you using in your raiserror? The following causes a
System.Data.SqlClient.SqlException to be raised in the client:

raiserror('Error Message', 17, 1)
return

The exceptions message property is "Error Message" in this case.
Misbah Arefin - 06 Mar 2008 17:46 GMT
try this in your stored proc

RAISEERROR(N'This is a message %s %d', -- message text
 16, --severity
 1, --state
 N'number', --first argument
 5); --second argument

and in your code you can get this error message in the SqlException object

try
{
 ExecuteSP();
}
catch(SqlException ex)
{
 Console.WriteLine(ex); //ex.Message will have the message text you used in
raiseerror
}

Signature

Misbah Arefin
https://mcp.support.microsoft.com/profile/MISBAH.AREFIN
http://www.linkedin.com/in/misbaharefin

> I think you misunderstood me... I already am raising errors in the stored
> proc's... I want to know how I can find out what the error was when I ran it
[quoted text clipped - 5 lines]
> >> Is there a way to get an error that is raised from a sql server stored
> >> procedure when executed from a sqlcommand object? thanks!

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.