[Mono-bugs] [Bug 63873][Nor] New - SqlCommand.ExecuteNonQuery aborts with error when passing DateTime Parameter to Stored Procedure

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Tue, 24 Aug 2004 17:52:09 -0400 (EDT)


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by mbazzano@unt.edu.ar.

http://bugzilla.ximian.com/show_bug.cgi?id=63873

--- shadow/63873	2004-08-24 17:52:09.000000000 -0400
+++ shadow/63873.tmp.9125	2004-08-24 17:52:09.000000000 -0400
@@ -0,0 +1,169 @@
+Bug#: 63873
+Product: Mono: Class Libraries
+Version: unspecified
+OS: 
+OS Details: Fedora Core 2 i686 2.6.5-1.358
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: Sys.Data.SqlClient
+AssignedTo: rodrigo@novell.com                            
+ReportedBy: mbazzano@unt.edu.ar               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: SqlCommand.ExecuteNonQuery aborts with error when passing DateTime Parameter to Stored Procedure
+
+Description of Problem:
+SqlCommand.ExecuteNonQuery aborts with error when passing DateTime
+Parameter to Stored Procedure.
+
+It throws the follwoing exception: " Unhandled Exception:
+System.Data.SqlClient.SqlException: Error converting data type varchar to
+datetime. "
+
+Steps to reproduce the problem:
+1. Create Sample Stored Procedure (Notice that the parameter is not even used)
+CREATE PROCEDURE sp_insert @TestPar1 varchar(50),
+
+@BirthDate datetime
+
+as
+
+INSERT INTO Employees(LastName,FirstName)
+
+	VALUES('Smith','John')
+GO
+2. Compile and run the following C# program (substitute the Login
+information in the connection string)
+
+using System;
+
+using System.Data;
+
+using System.Data.SqlClient;
+
+
+
+namespace ConsoleApplication2
+
+{
+
+	/// <summary>
+
+	/// Summary description for Class1.
+
+	/// </summary>
+
+	class Class1
+
+	{
+
+		/// <summary>
+
+		/// The main entry point for the application.
+
+		/// </summary>
+
+		[STAThread]
+
+		static void Main(string[] args)
+
+		{
+
+			//Conect
+
+			SqlConnection cnn = new SqlConnection("Data
+Source=xxx;UID=sa;PWD=xxx;Initial Catalog=Northwind");
+
+			cnn.Open();
+
+			Console.WriteLine(cnn.State);
+
+			SqlCommand cmd = new SqlCommand();
+
+			cmd.Connection = cnn;
+
+			cmd.CommandText = "sp_insert";
+
+			cmd.CommandType = CommandType.StoredProcedure;
+
+			object TestPar = System.DBNull.Value;
+
+			cmd.Parameters.Add("@TestPar1",SqlDbType.Int);
+
+			cmd.Parameters["@TestPar1"].Value = TestPar;
+
+			cmd.Parameters.Add("@BirthDate",DateTime.Now);
+
+			
+
+			Console.WriteLine(cmd.ExecuteNonQuery());
+
+			Console.ReadLine();
+
+
+
+		}
+
+	}
+
+}
+
+
+3. 
+
+Actual Results:
+This produces the following exceptions
+
+Unhandled Exception: System.Data.SqlClient.SqlException: Error converting
+data type varchar to datetime.
+in <0x0011d> System.Data.SqlClient.SqlConnection:ErrorHandler
+(object,Mono.Data.Tds.Protocol.TdsInternalErrorMessageEventArgs)
+in <0x0006a> (wrapper delegate-invoke)
+System.MulticastDelegate:invoke_void_object_TdsInternalErrorMessageEventArgs
+(object,Mono.Data.Tds.Protocol.TdsInternalErrorMessageEventArgs)
+in <0x00031> Mono.Data.Tds.Protocol.Tds:OnTdsErrorMessage
+(Mono.Data.Tds.Protocol.TdsInternalErrorMessageEventArgs)
+in <0x00056> (wrapper remoting-invoke-with-check)
+Mono.Data.Tds.Protocol.Tds:OnTdsErrorMessage
+(Mono.Data.Tds.Protocol.TdsInternalErrorMessageEventArgs)
+in <0x001ff> Mono.Data.Tds.Protocol.Tds:ProcessMessage
+(Mono.Data.Tds.Protocol.TdsPacketSubType)
+in <0x00056> (wrapper remoting-invoke-with-check)
+Mono.Data.Tds.Protocol.Tds:ProcessMessage
+(Mono.Data.Tds.Protocol.TdsPacketSubType)
+in <0x00130> Mono.Data.Tds.Protocol.Tds:ProcessSubPacket ()
+in <0x00047> Mono.Data.Tds.Protocol.Tds:NextResult ()
+in <0x00058> (wrapper remoting-invoke-with-check)
+Mono.Data.Tds.Protocol.Tds:NextResult ()
+in <0x00010> Mono.Data.Tds.Protocol.Tds:SkipToEnd ()
+in <0x0004a> (wrapper remoting-invoke-with-check)
+Mono.Data.Tds.Protocol.Tds:SkipToEnd ()
+in <0x000ac> Mono.Data.Tds.Protocol.Tds:ExecuteQuery (string,int,bool)
+in <0x0007b> (wrapper remoting-invoke-with-check)
+Mono.Data.Tds.Protocol.Tds:ExecuteQuery (string,int,bool)
+in <0x00046> Mono.Data.Tds.Protocol.Tds70:ExecProc
+(string,Mono.Data.Tds.TdsMetaParameterCollection,int,bool)
+in <0x0024e> System.Data.SqlClient.SqlCommand:Execute
+(System.Data.CommandBehavior,bool)
+in <0x00076> (wrapper remoting-invoke-with-check)
+System.Data.SqlClient.SqlCommand:Execute (System.Data.CommandBehavior,bool)
+in <0x00049> System.Data.SqlClient.SqlCommand:ExecuteNonQuery ()
+in <0x0004b> (wrapper remoting-invoke-with-check)
+System.Data.SqlClient.SqlCommand:ExecuteNonQuery ()
+in <0x00179> ConsoleApplication2.Class1:Main (string[])
+
+Expected Results:
+No errors. Compiled either with Mono or .NET.
+
+How often does this happen? 
+Always.
+
+Additional Information:
+There are other problems with
+System.Data.SqlClient.SqlParameter:InferSqlType when you pass it a
+DbNull.Value it does not infer the parameter type correctly (in this case
+any type will work).