[Mono-bugs] [Bug 82047][Wis] New - Error when trying to add a row with a DateTime field into an Italian SqlServer.

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Mon Jul 9 10:42:30 EDT 2007

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 s.martinz at caleidoscopio.it.


--- shadow/82047	2007-07-09 10:42:30.000000000 -0400
+++ shadow/82047.tmp.23571	2007-07-09 10:42:30.000000000 -0400
@@ -0,0 +1,128 @@
+Bug#: 82047
+Product: Mono: Class Libraries
+Version: 1.2
+OS: All
+OS Details: 
+Status: NEW   
+Priority: Wishlist
+Component: Sys.Data.SqlClient
+AssignedTo: mono-bugs at ximian.com                            
+ReportedBy: s.martinz at caleidoscopio.it               
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+Summary: Error when trying to add a row with a DateTime field into an Italian SqlServer.
+Description of Problem:
+Error when trying to add a new row with a DateTime field into an Italian
+Steps to reproduce the problem:
+1. Create a database with one table with one DateTime field on an Italian
+SqlServer database
+2. Run the following simple program
+  class Program
+  {
+    static void Main(string[] args)
+    {
+      SqlConnection conn = new SqlConnection("...");
+      string cmdText = "SELECT * FROM TestMONODateTime";
+      SqlCommand cmd = new SqlCommand(cmdText, conn);
+      SqlDataAdapter da = new SqlDataAdapter(cmd);
+      DataSet ds = new DataSet();
+      SqlCommandBuilder cmdBuilder = new SqlCommandBuilder(da);
+      da.Fill(ds);
+      DataTable dt = ds.Tables[0];
+      DataRow row = dt.NewRow();
+      row["DateTimeField"] = new DateTime(2007, 07, 10);
+      dt.Rows.Add(row);
+      da.Update(ds);
+    }
+  }
+Actual Results:
+New row cannot be added because DateTime format is not recognized as a
+valid one. Here is the detailed error (message is in italian, but basically
+it says that it is impossible to convert from varchar to datetime)
+Unhandled Exception: System.Data.SqlClient.SqlException: Si è verificato un
+errore durante la conversione del tipo di dati da varchar a datetime.
+  at System.Data.SqlClient.SqlConnection.ErrorHandler (System.Object
+sender, Mono.Data.Tds.Protocol.TdsInternalErrorMessageEventArgs e)
+[0x00000] in
+  at (wrapper delegate-invoke)
+  at Mono.Data.Tds.Protocol.Tds.OnTdsErrorMessage
+(Mono.Data.Tds.Protocol.TdsInternalErrorMessageEventArgs e) [0x0000b] in
+  at Mono.Data.Tds.Protocol.Tds.ProcessMessage (TdsPacketSubType subType)
+[0x000ef] in
+  at Mono.Data.Tds.Protocol.Tds.ProcessSubPacket () [0x00130] in
+  at Mono.Data.Tds.Protocol.Tds.NextResult () [0x0004a] in
+  at System.Data.SqlClient.SqlDataReader.NextResult () [0x00026] in
+  at System.Data.SqlClient.SqlDataReader..ctor
+(System.Data.SqlClient.SqlCommand command) [0x00000] 
+  at (wrapper remoting-invoke-with-check)
+System.Data.SqlClient.SqlDataReader:.ctor (System.Data.SqlClient.SqlCommand)
+  at System.Data.SqlClient.SqlCommand.ExecuteReader (CommandBehavior
+behavior) [0x0002f] in
+Expected Results:
+New row should be correctly added to the table in the database
+How often does this happen? 
+Additional Information:
+Here are the 2 (with Mono and MS.NET) actual queries run on the db, as seen
+using SQL Profiler:  
+ - with Mono on Linux: exec sp_executesql N'INSERT INTO [TestMONODateTime]
+([DateTimeField]) VALUES (@p1)', N'@p1 datetime',  @p1='Jul 10 2007
+12:00:00 AM'
+ - with MS.NET on Win: exec sp_executesql N'INSERT INTO [TestMONODateTime]
+([DateTimeField]) VALUES (@p1)', N'@p1 datetime', @p1 = 'lug 10 2007
+As you can see with MS.NET the month name is expressed in Italian and
+that's indipendent from the client thread culture. 
+With Mono, instead it is always expressed in English. This is due to the
+conversion performed in
+'/trunk/mcs/class/Mono.Data.Tds/Mono.Data.Tds.Protocol/Tds70.cs'; see the
+method FormatParameter() - when the parameter is datetime (it uses
+	...
+			case "datetime":
+				DateTime d = Convert.ToDateTime (parameter.Value);
+				value =
+String.Format(System.Globalization.CultureInfo.InvariantCulture, "'{0:MMM
+dd yyyy hh:mm:ss tt}'", d );
+	...
+I haven't tried, but I suppose the same issue could be repro on other
+localized SqlServer. 

More information about the mono-bugs mailing list