Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Strange SQLException (without message)  in C# ASP.NET page

Posted on 2008-06-10
6
Medium Priority
?
906 Views
Last Modified: 2008-06-12
I got the attached exception in my logs.  What's really strange is that the database actually got populated with the data from the call.  The stored procedure that get's called in MyCommon.SaveError is also wrapped in a transaction, so if the stored procedure failed it would have rolled back (the database is SQLServer 2005, so i'm using it's try{commit} catch{rollback} feature in the stored procedure).

SaveError simply makes a call to SqlCommand.ExecuteNonQuery(..)

I'm really scratching my head here, especially since the SqlException didn't have any message.

Any ideas?
System.Web.HttpUnhandledException: Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.Data.SqlClient.SqlException:  
   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
   at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
   at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
   at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
   at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe)
   at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
   at Gateway.Common.Model.StanError.SaveSTANError(StanError serror)
   at MyPage.Page_Load(Object sender, EventArgs e) in MyPage.aspx.cs:line 93
   at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
   at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
   at System.Web.UI.Control.OnLoad(EventArgs e)
   at System.Web.UI.Control.LoadRecursive()
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
   --- End of inner exception stack trace ---
   at System.Web.UI.Page.HandleError(Exception e)
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
   at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
   at System.Web.UI.Page.ProcessRequest()
   at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context)
   at System.Web.UI.Page.ProcessRequest(HttpContext context)
   at ASP.MyPage_aspx.ProcessRequest(HttpContext context)
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

Open in new window

0
Comment
Question by:davisnw
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 1

Expert Comment

by:travisrail
ID: 21755521
Would it be possible to see the section of C# code you think is bugged?
0
 
LVL 18

Accepted Solution

by:
Gary Davis earned 1500 total points
ID: 21756003
The stack trace shows it is in the ExecuteNonQuery(). Perhaps your try/catch is hiding the exception details.

Gary Davis
0
 
LVL 3

Author Comment

by:davisnw
ID: 21772933
The exception is caught in the Global.asax Application_Error, and is logged with the exception.ToString().  So the error handling code isn't hiding exception details.

The code itself is simply a run-of-the-mill execution of a stored procedure (attached below with parameter details removed)

So, does anyone know what the circumstances are when a SQLException occurs without any message?
public static void SaveError(StanError serror)
{
    const string currentSql = "dbo.sp_AddError";
    string connectionString = ConfigurationManager.ConnectionStrings["ConnectionStringName"].ConnectionString;
    using (SqlConnection conn = new SqlConnection(connectionString))
    {
        conn.Open();
        using (SqlCommand cmd = new SqlCommand(currentSql, conn))
        {
             cmd.CommandType = System.Data.CommandType.StoredProcedure;
             cmd.Parameters.AddWithValue("param1", param1Value );
 
                          ...
 
             cmd.Parameters.AddWithValue("paramN", paramNValue );
             cmd.ExecuteNonQuery();
        }
    }           
}
 
 
 
PROCEDURE dbo.sp_AddError
	@params1 .. paramN
 
AS
 
declare @error nvarchar(max)
 
BEGIN TRY
	BEGIN TRANSACTION
			INSERT INTO dbo.tbl_STAN_Error(param1..paramN)
				VALUES (paramValues1...paramValuesN)
 
	COMMIT TRANSACTION
END TRY
BEGIN CATCH
	ROLLBACK TRANSACTION
	SELECT @error = @error + ' :__: ' + ERROR_MESSAGE()
	RAISERROR (@error, 16,1)
END CATCH

Open in new window

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Author Comment

by:davisnw
ID: 21773672
Ok.  So I guess the exception handling is hiding exception details.

The SQLException class has an Errors property which is a collection of SQLError objects.  Exception.ToString() doesn't show that collection.  So I need to modify my handling of SQLExceptions to also log what is in the Errors collection.  It appears that if the Errors collection is filled out, a message may not always be generated.

Points go to gardavis for pointing me in the right direction.

Thanks!
0
 
LVL 18

Expert Comment

by:Gary Davis
ID: 21773982
Thanks.

So what was the hidden error?
0
 
LVL 3

Author Comment

by:davisnw
ID: 21774014
Not sure yet at this point.  I'll have to wait until the logging changes get put into production.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question