|
.net
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Error messagesNot 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 try{
cmd.ExecuteNonQuery(); } catch (SqlException se){ Response.Write(se.Message); } Show quoteHide quote "tshad" <tscheider***@ftsolutions.com> wrote in message C:\Inetpub\wwwroot\staffingworkshop\applicant\secure\viewPositions.aspx:linenews: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 > > 566 C:\Inetpub\wwwroot\staffingworkshop\applicant\secure\viewPositions.aspx:line> at ASP.viewPositions_aspx.Page_Load(Object sender, EventArgs e) in > > 189 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication+IExecutionSte> 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 > p.Execute() > at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& C:\Inetpub\wwwroot\staffingworkshop\applicant\secure\viewPositions.aspx:line> 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 > > 566 C:\Inetpub\wwwroot\staffingworkshop\applicant\secure\viewPositions.aspx:line> at ASP.viewPositions_aspx.Page_Load(Object sender, EventArgs e) in > > 189 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication+IExecutionSte> 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 > p.Execute() Show quoteHide quote > at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& > completedSynchronously) > > Thanks, > > Tom > > "Buddy Ackerman" <buddy_N0SPAM@buddyackerman.com> wrote in message Actually, you're right.news:OonwOnM4FHA.3684@TK2MSFTNGP10.phx.gbl... > try{ > cmd.ExecuteNonQuery(); > } > catch (SqlException se){ > Response.Write(se.Message); > } > 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 >> >> > > 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? -- Show quoteHide quoteJoshua Mitts jos***@msn.com "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 >>> >>> >> >> > >
VS2005: Code "gramatically" correct..
ObjectDataSource with Complex Objects and 2 way Databinding Is there any IsNumeric in C#? Impersonate - Urgent Update to VS2005 How to use new ASP.NET2 Tree Control? Binary data stored in SQL Server: can't read from ASP.NET, *can* read from Access? Storing OleDBConnection in Session ASP.NET 2.0: Login control Multiple forms on aspx and ENTER key |
|||||||||||||||||||||||