Home All Groups Group Topic Archive Search About
Author
3 Nov 2005 10:46 PM
tshad
If you get an exception or SqlException, how do you get the actual message?

Not the detailed breakdown, but the actual message.

For example, in the following message, I would like to find just "Incorrect
syntax near the keyword 'and'." or "System.Data.SqlClient.SqlException:
Incorrect syntax near the keyword 'and'."

instead of:

errMessage = System.Web.HttpUnhandledException: Exception of type
System.Web.HttpUnhandledException was thrown. --->
System.Data.SqlClient.SqlException: Incorrect syntax near the keyword 'and'.
  at ASP.viewPositions_aspx.BindData(String SortFieldName) in
C:\Inetpub\wwwroot\staffingworkshop\applicant\secure\viewPositions.aspx:line
566
  at ASP.viewPositions_aspx.Page_Load(Object sender, EventArgs e) in
C:\Inetpub\wwwroot\staffingworkshop\applicant\secure\viewPositions.aspx:line
189
  at System.Web.UI.Control.OnLoad(EventArgs e)
  at System.Web.UI.Control.LoadRecursive()
  at System.Web.UI.Page.ProcessRequestMain()
  --- End of inner exception stack trace ---
  at System.Web.UI.Page.HandleError(Exception e)
  at System.Web.UI.Page.ProcessRequestMain()
  at System.Web.UI.Page.ProcessRequest()
  at System.Web.UI.Page.ProcessRequest(HttpContext context)
  at
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication+IExecutionStep.Execute()
  at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&
completedSynchronously)errMessage = System.Web.HttpUnhandledException:
Exception of type System.Web.HttpUnhandledException was thrown. --->
System.Data.SqlClient.SqlException: Incorrect syntax near the keyword 'and'.
  at ASP.viewPositions_aspx.BindData(String SortFieldName) in
C:\Inetpub\wwwroot\staffingworkshop\applicant\secure\viewPositions.aspx:line
566
  at ASP.viewPositions_aspx.Page_Load(Object sender, EventArgs e) in
C:\Inetpub\wwwroot\staffingworkshop\applicant\secure\viewPositions.aspx:line
189
  at System.Web.UI.Control.OnLoad(EventArgs e)
  at System.Web.UI.Control.LoadRecursive()
  at System.Web.UI.Page.ProcessRequestMain()
  --- End of inner exception stack trace ---
  at System.Web.UI.Page.HandleError(Exception e)
  at System.Web.UI.Page.ProcessRequestMain()
  at System.Web.UI.Page.ProcessRequest()
  at System.Web.UI.Page.ProcessRequest(HttpContext context)
  at
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication+IExecutionStep.Execute()
  at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&
completedSynchronously)

Thanks,

Tom

Author
3 Nov 2005 10:56 PM
Buddy Ackerman
try{
    cmd.ExecuteNonQuery();
}
catch (SqlException se){
    Response.Write(se.Message);
}




Show quoteHide quote
"tshad" <tscheider***@ftsolutions.com> wrote in message
news:u0408hM4FHA.2676@TK2MSFTNGP15.phx.gbl...
> If you get an exception or SqlException, how do you get the actual
message?
>
> Not the detailed breakdown, but the actual message.
>
> For example, in the following message, I would like to find just
"Incorrect
> syntax near the keyword 'and'." or "System.Data.SqlClient.SqlException:
> Incorrect syntax near the keyword 'and'."
>
> instead of:
>
> errMessage = System.Web.HttpUnhandledException: Exception of type
> System.Web.HttpUnhandledException was thrown. --->
> System.Data.SqlClient.SqlException: Incorrect syntax near the keyword
'and'.
>   at ASP.viewPositions_aspx.BindData(String SortFieldName) in
>
C:\Inetpub\wwwroot\staffingworkshop\applicant\secure\viewPositions.aspx:line
> 566
>   at ASP.viewPositions_aspx.Page_Load(Object sender, EventArgs e) in
>
C:\Inetpub\wwwroot\staffingworkshop\applicant\secure\viewPositions.aspx:line
> 189
>   at System.Web.UI.Control.OnLoad(EventArgs e)
>   at System.Web.UI.Control.LoadRecursive()
>   at System.Web.UI.Page.ProcessRequestMain()
>   --- End of inner exception stack trace ---
>   at System.Web.UI.Page.HandleError(Exception e)
>   at System.Web.UI.Page.ProcessRequestMain()
>   at System.Web.UI.Page.ProcessRequest()
>   at System.Web.UI.Page.ProcessRequest(HttpContext context)
>   at
>
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication+IExecutionSte
p.Execute()
>   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&
> completedSynchronously)errMessage = System.Web.HttpUnhandledException:
> Exception of type System.Web.HttpUnhandledException was thrown. --->
> System.Data.SqlClient.SqlException: Incorrect syntax near the keyword
'and'.
>   at ASP.viewPositions_aspx.BindData(String SortFieldName) in
>
C:\Inetpub\wwwroot\staffingworkshop\applicant\secure\viewPositions.aspx:line
> 566
>   at ASP.viewPositions_aspx.Page_Load(Object sender, EventArgs e) in
>
C:\Inetpub\wwwroot\staffingworkshop\applicant\secure\viewPositions.aspx:line
> 189
>   at System.Web.UI.Control.OnLoad(EventArgs e)
>   at System.Web.UI.Control.LoadRecursive()
>   at System.Web.UI.Page.ProcessRequestMain()
>   --- End of inner exception stack trace ---
>   at System.Web.UI.Page.HandleError(Exception e)
>   at System.Web.UI.Page.ProcessRequestMain()
>   at System.Web.UI.Page.ProcessRequest()
>   at System.Web.UI.Page.ProcessRequest(HttpContext context)
>   at
>
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication+IExecutionSte
p.Execute()
Show quoteHide quote
>   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&
> completedSynchronously)
>
> Thanks,
>
> Tom
>
>
Are all your drivers up to date? click for free checkup

Author
3 Nov 2005 11:17 PM
tshad
"Buddy Ackerman" <buddy_N0SPAM@buddyackerman.com> wrote in message
news:OonwOnM4FHA.3684@TK2MSFTNGP10.phx.gbl...
> try{
>    cmd.ExecuteNonQuery();
> }
> catch (SqlException se){
>    Response.Write(se.Message);
> }
>

Actually, you're right.

But how do you do that from the Application Error section of the Global.asax
file.  That was where I got the long message.

Also,

I tried doing:

Catch ex as SQLexception
   RcdCount = 0
   If ex.number = 7619 then
    ErrorMessage.text = "<br>There were only ignored words in your list.
These are words that are too general to search such as: the and of.<br><br>"
   end if
   ErrorMessage.Text = "<br>Error message 2"
    trace.warn("Sql Error from SqlException = " & ex.message)
Catch ex2 as Exception
   ErrorMessage.TExt = "<br>Error Message 3"
    trace.warn("Regular Error = " & ex2.message)
'    throw ex
end try

And it always takes the 1st Catch and never the 2nd.

How do I tell if this is an SqlException or just a normal exception?

I saw an example program where they did this, but what is the point if the
first one is always going to take the exception?

Thanks,

Tom
Show quoteHide quote
>
>
>
> "tshad" <tscheider***@ftsolutions.com> wrote in message
> news:u0408hM4FHA.2676@TK2MSFTNGP15.phx.gbl...
>> If you get an exception or SqlException, how do you get the actual
> message?
>>
>> Not the detailed breakdown, but the actual message.
>>
>> For example, in the following message, I would like to find just
> "Incorrect
>> syntax near the keyword 'and'." or "System.Data.SqlClient.SqlException:
>> Incorrect syntax near the keyword 'and'."
>>
>> instead of:
>>
>> errMessage = System.Web.HttpUnhandledException: Exception of type
>> System.Web.HttpUnhandledException was thrown. --->
>> System.Data.SqlClient.SqlException: Incorrect syntax near the keyword
> 'and'.
>>   at ASP.viewPositions_aspx.BindData(String SortFieldName) in
>>
> C:\Inetpub\wwwroot\staffingworkshop\applicant\secure\viewPositions.aspx:line
>> 566
>>   at ASP.viewPositions_aspx.Page_Load(Object sender, EventArgs e) in
>>
> C:\Inetpub\wwwroot\staffingworkshop\applicant\secure\viewPositions.aspx:line
>> 189
>>   at System.Web.UI.Control.OnLoad(EventArgs e)
>>   at System.Web.UI.Control.LoadRecursive()
>>   at System.Web.UI.Page.ProcessRequestMain()
>>   --- End of inner exception stack trace ---
>>   at System.Web.UI.Page.HandleError(Exception e)
>>   at System.Web.UI.Page.ProcessRequestMain()
>>   at System.Web.UI.Page.ProcessRequest()
>>   at System.Web.UI.Page.ProcessRequest(HttpContext context)
>>   at
>>
> System.Web.CallHandlerExecutionStep.System.Web.HttpApplication+IExecutionSte
> p.Execute()
>>   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&
>> completedSynchronously)errMessage = System.Web.HttpUnhandledException:
>> Exception of type System.Web.HttpUnhandledException was thrown. --->
>> System.Data.SqlClient.SqlException: Incorrect syntax near the keyword
> 'and'.
>>   at ASP.viewPositions_aspx.BindData(String SortFieldName) in
>>
> C:\Inetpub\wwwroot\staffingworkshop\applicant\secure\viewPositions.aspx:line
>> 566
>>   at ASP.viewPositions_aspx.Page_Load(Object sender, EventArgs e) in
>>
> C:\Inetpub\wwwroot\staffingworkshop\applicant\secure\viewPositions.aspx:line
>> 189
>>   at System.Web.UI.Control.OnLoad(EventArgs e)
>>   at System.Web.UI.Control.LoadRecursive()
>>   at System.Web.UI.Page.ProcessRequestMain()
>>   --- End of inner exception stack trace ---
>>   at System.Web.UI.Page.HandleError(Exception e)
>>   at System.Web.UI.Page.ProcessRequestMain()
>>   at System.Web.UI.Page.ProcessRequest()
>>   at System.Web.UI.Page.ProcessRequest(HttpContext context)
>>   at
>>
> System.Web.CallHandlerExecutionStep.System.Web.HttpApplication+IExecutionSte
> p.Execute()
>>   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&
>> completedSynchronously)
>>
>> Thanks,
>>
>> Tom
>>
>>
>
>
Author
4 Nov 2005 12:15 AM
Joshua Mitts
In Global.asax, you need to call Server.GetLastError() to get the exception.
Then, you need to test if the Exception returned is a SqlException. In C#,
you use the is or as operator for this purpose, i.e.:

<pseudo-code>
Exception ex = Server.GetLastError();
SqlException sqlex = ex as SqlException;
if (sqlex != null) // ex is SqlException
{
    // process it as a sqlexception
}

I don't know the equivilent operator in VB for is or as -- anyone else know?

--

Joshua Mitts
jos***@msn.com

Show quoteHide quote
"tshad" <tscheider***@ftsolutions.com> wrote in message
news:ud8iNzM4FHA.2640@TK2MSFTNGP09.phx.gbl...
> "Buddy Ackerman" <buddy_N0SPAM@buddyackerman.com> wrote in message
> news:OonwOnM4FHA.3684@TK2MSFTNGP10.phx.gbl...
>> try{
>>    cmd.ExecuteNonQuery();
>> }
>> catch (SqlException se){
>>    Response.Write(se.Message);
>> }
>>
>
> Actually, you're right.
>
> But how do you do that from the Application Error section of the
> Global.asax file.  That was where I got the long message.
>
> Also,
>
> I tried doing:
>
> Catch ex as SQLexception
>   RcdCount = 0
>   If ex.number = 7619 then
>    ErrorMessage.text = "<br>There were only ignored words in your list.
> These are words that are too general to search such as: the and
> of.<br><br>"
>   end if
>   ErrorMessage.Text = "<br>Error message 2"
>    trace.warn("Sql Error from SqlException = " & ex.message)
> Catch ex2 as Exception
>   ErrorMessage.TExt = "<br>Error Message 3"
>    trace.warn("Regular Error = " & ex2.message)
> '    throw ex
> end try
>
> And it always takes the 1st Catch and never the 2nd.
>
> How do I tell if this is an SqlException or just a normal exception?
>
> I saw an example program where they did this, but what is the point if the
> first one is always going to take the exception?
>
> Thanks,
>
> Tom
>>
>>
>>
>> "tshad" <tscheider***@ftsolutions.com> wrote in message
>> news:u0408hM4FHA.2676@TK2MSFTNGP15.phx.gbl...
>>> If you get an exception or SqlException, how do you get the actual
>> message?
>>>
>>> Not the detailed breakdown, but the actual message.
>>>
>>> For example, in the following message, I would like to find just
>> "Incorrect
>>> syntax near the keyword 'and'." or "System.Data.SqlClient.SqlException:
>>> Incorrect syntax near the keyword 'and'."
>>>
>>> instead of:
>>>
>>> errMessage = System.Web.HttpUnhandledException: Exception of type
>>> System.Web.HttpUnhandledException was thrown. --->
>>> System.Data.SqlClient.SqlException: Incorrect syntax near the keyword
>> 'and'.
>>>   at ASP.viewPositions_aspx.BindData(String SortFieldName) in
>>>
>> C:\Inetpub\wwwroot\staffingworkshop\applicant\secure\viewPositions.aspx:line
>>> 566
>>>   at ASP.viewPositions_aspx.Page_Load(Object sender, EventArgs e) in
>>>
>> C:\Inetpub\wwwroot\staffingworkshop\applicant\secure\viewPositions.aspx:line
>>> 189
>>>   at System.Web.UI.Control.OnLoad(EventArgs e)
>>>   at System.Web.UI.Control.LoadRecursive()
>>>   at System.Web.UI.Page.ProcessRequestMain()
>>>   --- End of inner exception stack trace ---
>>>   at System.Web.UI.Page.HandleError(Exception e)
>>>   at System.Web.UI.Page.ProcessRequestMain()
>>>   at System.Web.UI.Page.ProcessRequest()
>>>   at System.Web.UI.Page.ProcessRequest(HttpContext context)
>>>   at
>>>
>> System.Web.CallHandlerExecutionStep.System.Web.HttpApplication+IExecutionSte
>> p.Execute()
>>>   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step,
>>> Boolean&
>>> completedSynchronously)errMessage = System.Web.HttpUnhandledException:
>>> Exception of type System.Web.HttpUnhandledException was thrown. --->
>>> System.Data.SqlClient.SqlException: Incorrect syntax near the keyword
>> 'and'.
>>>   at ASP.viewPositions_aspx.BindData(String SortFieldName) in
>>>
>> C:\Inetpub\wwwroot\staffingworkshop\applicant\secure\viewPositions.aspx:line
>>> 566
>>>   at ASP.viewPositions_aspx.Page_Load(Object sender, EventArgs e) in
>>>
>> C:\Inetpub\wwwroot\staffingworkshop\applicant\secure\viewPositions.aspx:line
>>> 189
>>>   at System.Web.UI.Control.OnLoad(EventArgs e)
>>>   at System.Web.UI.Control.LoadRecursive()
>>>   at System.Web.UI.Page.ProcessRequestMain()
>>>   --- End of inner exception stack trace ---
>>>   at System.Web.UI.Page.HandleError(Exception e)
>>>   at System.Web.UI.Page.ProcessRequestMain()
>>>   at System.Web.UI.Page.ProcessRequest()
>>>   at System.Web.UI.Page.ProcessRequest(HttpContext context)
>>>   at
>>>
>> System.Web.CallHandlerExecutionStep.System.Web.HttpApplication+IExecutionSte
>> p.Execute()
>>>   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step,
>>> Boolean&
>>> completedSynchronously)
>>>
>>> Thanks,
>>>
>>> Tom
>>>
>>>
>>
>>
>
>

Bookmark and Share

Post Thread options