.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

SQL Server try-catch inner exception message conundrum

Posted By:      Posted Date: December 04, 2010    Points: 0   Category :Sql Server


The following SQL statement below is a good example of some SQL that throws an exception with nested details. It seems in the catch part of the statement I can only get outer exception details Could not create constraint. See previous errors (not very useful!). What I want to get is the inner exception message:

Introducing FOREIGN KEY constraint 'FK_TWO' on table 'TABLE2' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints (you can get this message by running the code without try-catch).

In the Catch block, how can this be achieved in T-SQL? If not is this something that can be fixed in SQL going forward, where can I send this request?


      CHAR(50) NOT NULL);



View Complete Post

More Related Resource Links

SQL Server 2005 Try and Catch Exception Handling

I'm pretty excited to see that there is some real error handling for T-SQL code in SQL Server 2005. It's pretty painful to have your wonderfully architected .NET solution tainted by less-than-VBScript error handling for stored procedures in the database. The big difference being the addition of TRY..CATCH blocks. Let's take a look:

throw exception message giving internal server error on live site


using vb.net/asp.net 2005

when a user enters a bad email I am doing a check on this and throwing an exception message as follows, this works fine on the test site but for some reason the same code on the live site gives a "internal server error" (http code 500).  The code below:

            If isThisEmailValid(strEmailThatTheUserEntered) Then
		'do something


                Throw New Exception("You entered a bad email address.")

            End If

not certain why this is happening, I assume that it's some server or config difference between the test and live sites.  has anyone seen this before?  For a quick fix i'm registering javascript alert and showing the same text so it works but I would like to figure out why the code above is not working.

as always, thanks for your feedback


reader.getordinal("column_may_not_exist") how to catch the exception?



would any body please help me to catch the exception if the column doesnot exist as my table columns are not static.

sometimes its throwing me indexoutofrange exception as the column doesnot exist

thanks for the help guys

Data Points: SQL Server 2005 XML Support, Exception Handling, and More


SQL Server 2005 includes several important improvements to the Transact-SQL (T-SQL) language. One added feature is a new kind of trigger that fires when data definition language (DDL) statements run.

John Papa

MSDN Magazine May 2006

Error Handling: Throwing Custom Exception Types from a Managed COM+ Server Application


Exception handling semantics in .NET are based on type, so you can create custom exceptions that have their own properties and methods. In .NET, exceptions are first-class citizens, and since they're the built-in error handling mechanism, all .NET-compliant languages must support exceptions. In addition, COM+ services are available to .NET code as Enterprise Services, so you can leverage exceptions in your Enterprise Services design.In this article the author describes custom exceptions, throwing exceptions across COM interop boundaries, and working with Enterprise Services.

Bob DeRemer

MSDN Magazine March 2004

How to CATCH "Invalid postback or callback argument" exception?



How can I catch this exception? I do not want it to stop my page execution. Can/Should I do that?

Server Error in '/' Application.
Invalid postback or callback argument.  Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page.  For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them.  If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: Invalid postback or callback argument.  Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page.  For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally

How to Add Custom SOAP Headers Into The Server Response Message in WSE3.0?

Hi Dear All, Assuming I am the service provider, may i know how many ways are there to insert a custom header into the server response message? So far I tried several ways, and it can be done in custom SoapFilters (by playing with SOAPEnvelope object), and SoapExtension (SOAPMessage object). Just wondering if this could be done at web service class by specifying a SOAPHeader attribute, just like adding a SOAPHeader into the SOAP request message at consumer side? If can, it might be much smarter than SoapFilter and SoapExtension.   Thanks in advance!   Best Regards, Charles

The formatter threw an exception while trying to deserialize the message

Hi I got this error when programming in C# 2008 The formatter threw an exception when trying to deserialize the message: Error while trying to deserialize parameter http://tempuri.org/:GetListSitesResponse. The InnerException message was' Error on line 1, position 314. The item 'http://tempuri.org/:anyType' contains data data contract 'http://tempuri.org/:Site'. The deserializer has no knowledge of any type that is assigned to this contract. Add the type corresponding to 'Site' to the list of known types (eg, using the attribute KnownTypeAttribute or adding it to the list of known types passed to DataContractSerializer). '. See InnerException for more information. This happen in my button_click event (this is a project on C# 2008 express windows form application) private void button1_Click(object sender, EventArgs e)         {             SiteDevelopmentReference.Service1SoapClient sd = new SiteDevelopmentReference.Service1SoapClient();             listBox1.Items.AddRange(sd.GetListSites().ToArray());                            } I have a service reference from another project

Unable to catch WCF EndpointNotFound exception in SecurityToken.GetToken( . )

I have a set of WCF services that I am integrating with, I can not change them in any way because they are provided by a third party. I use a username/password scheme to authenticate with the services. If the services are not available I get an exception (EndPointNotFoundException) from the SecurityTokenProvider class that I can not catch. I understand why the exception is being thrown, I just need to know how I can handle it so that I can gracefully handle the errors in the user interface. Is there a way I can catch this exception or a better way to handle this scenario? The Exception The exception is thrown from System.IdentityModel.Selectors.SecurityTokenProvider : GetToken( TimeSpan timeout ) public SecurityToken GetToken(TimeSpan timeout) {    SecurityToken token = this.GetTokenCore(timeout);     if (token == null)    {        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.TokenProviderUnableToGetToken, this)));    }     return token;} The channel open part When I open the channel I have it wrapped in exception handling, but none of it seems to trap the SecurityToken exception. I am using the ExceptionHandlingProxyWrapperBase try{    this.Open();} catch( EndpointNotFoundException epnfe ){    // Handle the exception} catch( E

clr assembly in sql server - working directory? and exception question

Hello, I have a small assembly in sql server 2008... it's pretty simple, but in the very rare circumstance that it may throw an exception I am catching it and writting to a log file. something like: using (StreamWriter sr = new StreamWriter(@".\ErrorLog.txt", true)) { sr.WriteLine("{0:G} ===> {1}", DateTime.Now, ex.Message); } I believe that should write the file to the working directory... 1. what would the working directory be for sql server 2008? the binn directory? 2. what would happen if a clr assembly added to sql server throws an exception that is not handled by your clr code?

SQL Server Configuration Manager Exception: 0x80010105

We're running SQL Server 2008 Standard edition version 10.0.2531.0 (SP1) 64-bit.  It is running on Windows Server 2008 R2. Whenever I connect to the SQL Server Configuration Manager, and look at the SQL Server Services, I get the message : The server threw an exception. [0x80010105]. Suggestions?Clint

RPC Server Exception

System.Management.ManagementScope ms = new System.Management.ManagementScope("\\\\" + stringMachineName + "\\root\\cimv2", co); oq = new System.Management.ObjectQuery("SELECT * FROM Win32_processor"); query = new ManagementObjectSearcher(ms, oq); queryCollection = query.Get(); return queryCollection;   well guys i am trying to access remote system but in doing this some machines give mein following exception  System.interop.Runtime.COmException RPC SERVER IS unavailable (Exception from Hresult:0x800706BA)     can u help me this how to solve this JK

Internal Server Error Exception when Searching (in CoreResultsWebPart::OnInit)

Hello, We are encountering an "Internal server error exception" when we attempt to search. The relevant error in the ULS log is:   CoreResultsWebPart::OnInit: Exception initializing: System.NullReferenceException: Object reference not set to an instance of an object.     at Microsoft.Office.Server.Search.WebControls.CoreResultsWebPart.SetPropertiesOnQueryReader()     at Microsoft.Office.Server.Search.WebControls.CoreResultsWebPart.OnInit(EventArgs e)   This is occurring on a fresh install of SharePoint Server 2010 Standard Edition running on a single-server farm.  We have tried:   ensuring that hotfix 976462 is installed (it is) ensuring that the "SharePoint Server Search" and "Search Query and Site Settings Service" services are running (they are) removing, then reinstalling the search application (tried, but with no luck) appending ":80" to the host of portion of the search result url to see if we get a different result (we do not) ensuring that the application pool is assigned correctly (it is) restarting the timer service restarting the search service rebooting For the sake of conversation, we'll say the server is named "pharaoh". It has the following AAMs: http://pharaoh:8888, Default Zone  (Central Admin) http://pharaoh, Default Zone   All services and applicati

Throwinfg Exception from a faulted Message.

Hi I havetransparent proxy that recieves a message from the service. I have to test what happens when the service throws any exception. When I generate the proxy from the "Add Service Reference" from visual studio, it works ok. If I throw a InvalidOperationException on the service it reaches the client with the traditional FaultException. But with my manyally created proxy, it only recieves the faulted messate ( the IsFault attribute is true ) but it does not throw the exception. Here are the exmamples: Host: Contract:   [ServiceContract(Namespace = "http://my.namespace.com")] public interface ICalculadora { [OperationContract] int LancaException(string codigo); }   Service:   public class Service : ICalculadora { public int LancaException(string codigo) { if (codigo == "exception") { throw new InvalidOperationException("Operação ilegal", new DivideByZeroException("Divisão por zero")); } else if (codigo == "numero") { return 32; } else if (codigo == "fault") { InvalidOperationException invEx = new InvalidOperationException("Operacao inválida dentro da faulta"); //throw new FaultException<InvalidOperation

ws-addressing 'Action' required message part not signed exception

I have a WCF client calling a Java-based service. The service vendor is supporting WCF clients. The WCF client binding uses authenticationMode="MutualCertificate", messageVersion="Soap11WSAddressing10" and the message is signed and encrypted (SignBeforeEncrypt). WCF, in this case, is automatically signing all the ws-addressing ( <Action>, <MessageID> and <To> ) headers. The message gets to the service and comes back with what appears to be valid encrypted data in the response BUT the client is throwing a "The 'Action', 'http://www.w3.org/2005/08/addressing' required message part was not signed" exception (mscorlib). Questions: Is there a way to NOT sign the ws-addressing headers in the request message while still using both signing and encryption (X.509 certs)? If the client DOES sign the ws-addressing headers in the request, is there a way to configure WCF to accept UNsigned ws-addressing headers in the response? If the answer is NO on both questions, I guess I will have to ask the service vendor to sign the ws-addressing headers in the response. Thanks.

WCF server too busy error message

I have a remote WCF service that has a method that returns the error below when I try to invoke a method that returns a List<T> of an entity (from WcfTestClient). There are virutally no other users on the box.  The other 'non-list' methods (update ,insert) work fine when called from WcfTestClient. Help greatly appreciated.  Somewhat of a n00b at WCF.     The HTTP service located at *****.svc is too busy. Server stack trace:    at System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason)   at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)   at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)   at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessag
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend