Home Dashboard Directory Help
Search

SQL InternalSmiConnection threw an exception of type 'System.InvalidCastException by Jack_Sacramento


Status: 

Closed
 as By Design Help for as By Design


1
0
Sign in
to vote
Type: Bug
ID: 541609
Opened: 3/12/2010 11:54:40 AM
Access Restriction: Public
1
Workaround(s)
view
0
User(s) can reproduce this bug

Description

VS 2008 Professional SP1
Microsoft SQL Server 2005 Standard Edition Version 9.00.3353.00

VS console app ExecuteNonQuery() causes error in SQL

EventSink = '_updateID.EventSink' threw an exception of type 'System.InvalidCastException'

{"Unable to cast object of type 'System.Data.SqlClient.SqlInternalConnectionTds' to type 'System.Data.SqlClient.SqlInternalConnectionSmi'."}

Insert succeeds but _updateID.ExecuteNonQuery() returns -1

_updateID {System.Data.SqlClient.SqlCommand} contains SQL error response in
Non-Public Members
     EventSink '_updateID.EventSink' threw an exception of type 'System.InvalidCastException' System.Data.SqlClient.SqlCommand.CommandEventSink {System.InvalidCastException}
Details
Sign in to post a comment.
Posted by Jack_Sacramento on 3/15/2010 at 2:35 PM
Please close this incident.
Posted by Jack_Sacramento on 3/15/2010 at 2:30 PM
Thanks for the help Microsoft team.
Posted by Microsoft on 3/15/2010 at 2:24 PM
Hi

ExecuteNonQuery returns -1 because the stored procedure you are running has "SET NOCOUNT ON" in the beginning. This optimization stops the message that shows the count of the number of rows affected by a Transact-SQL statement or stored procedure from being returned as part of the result set. Thus, ExecuteNonQuery does not receive this information from SQL Server and returns -1.

This behavior is by design. Please refer to SQL Books online for more details about NOCOUNT option here: http://msdn.microsoft.com/en-us/library/ms189837.aspx.

I also mentioned the solution in Workaround section.

Note for the exception message in debugger's Watch or Locals window (EventSink in non-public properties of SqlCommand) - this is a different issue. EventSink property is internally used in a different scenario (SQL context connections) and is never used for regular connectiosn to SQL Server. Since debugger queries all properties of the object, EventSink raises exception as expected.

Thanks for your report - let us know if you have more questions.

Regards,
Nissim Natanov,
SQL Connectivity Team, Microsoft
Posted by Microsoft on 3/15/2010 at 1:49 AM
Thank you for your feedback, We are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Posted by Jack_Sacramento on 3/12/2010 at 2:23 PM
Why is this exception not thrown back to the application?
Posted by Jack_Sacramento on 3/12/2010 at 2:11 PM
More info from stack trace. Looks like the error is thrown in the System.Data.SQLClient

StackTrace " at System.Data.SqlClient.SqlCommand.get_InternalSmiConnection()\r\n at System.Data.SqlClient.SqlCommand.get_EventSink()"    string

I have reproduced using a different stored procedure.
Posted by Jack_Sacramento on 3/12/2010 at 12:06 PM
MS please contact me regarding the attached file.
Sign in to post a workaround.
Posted by Nissim Natanov on 3/15/2010 at 2:21 PM
Remove SET NOCOUNT ON from the beginning of the [IJISPROC_InsertIDScore] stored procedure. Please refer to http://msdn.microsoft.com/en-us/library/ms189837.aspx for more details.