[Mono-devel-list] DateTime Parameters in MSSQL Server

Hubert FONGARNAND informatique.internet at fiducial.fr
Tue Jul 12 10:30:39 EDT 2005


Le Mardi 12 Juillet 2005 15:50, Hubert FONGARNAND a écrit :
I've found where is the problem

Fri Jan 7 08:26:07 2005 suresh has submitted a patch wich change the format of 
datetime parameters from :
 value = String.Format(System.Globalization.CultureInfo.InvariantCulture,
                                           '{0:MM/dd/yyyy hh:mm:ss tt}'", d );

to
value = String.Format(System.Globalization.CultureInfo.InvariantCulture,
		 "'{0:MMM dd yyyy hh:mm:ss tt}'", d );

i've restored the old line (0:MM/dd/yyyy hh:mm:ss tt) and it works for me now!
but I think this problems comes from the database culture...

Is it possible that the Tds drivers could adapt it automatically to the 
database??? 
I think, it's a very bad idea to change the mono code source each time you 
change your database...


thanks
> The problems comes from the method
>
> private string FormatParameter (TdsMetaParameter parameter)
>
> in Mono.Data.tds.protocol
>
> wich encode parameters in order to send them to SQL Server. With MS.NET,
> parameters are send using a binary format, with mono, parameters are sent
> using the "string" format...
> It's a problem when dealing with dates :
> case "datetime":
>                                DateTime d = (DateTime)parameter.Value;
>                                 value =
> String.Format(System.Globalization.CultureInfo.InvariantCulture,
>                                                       "'{0:MMM dd yyyy
> hh:mm:ss tt}'", d );
>                                 break;
>
> Is the format "MMM dd yyyy hh:mm:ss tt" correct? for all SQL Server 2000
> (french version)
>
> Le Mardi 12 Juillet 2005 15:42, Chris van Wyk a écrit :
> > Hi,
> >
> > Datetime has also been giving me huge amounts of problems.
> >
> > The work around for me was to convert the item using ToString("s"). If
> > you are going to use stored procs, you will need to modify your stored
> > proc parameters in the sql statement to string in stead of datetime.
> >
> > I have also been able to get the Microsoft.ApplicationBlocks.Data going
> > with modification to specific DateTime parameter formatting.
> >
> > There seems to be problems with the data adapter using the sqlhelper from
> > the above. I am getting concurrency errors on updates for instance. If
> > someone else has had concurrency errors please let me know as I have been
> > able to work round this, but I'm not sure if it is a bug in Mono.
> >
> > I am using 1.1.7 and have not tested the above on 1.1.8
> >
> > Regards
> > Chris
> >
> > > -----Original Message-----
> > > From: mono-devel-list-bounces at lists.ximian.com [mailto:mono-devel-list-
> > > bounces at lists.ximian.com] On Behalf Of Hubert FONGARNAND
> > > Sent: 12 July 2005 03:28 PM
> > > To: mono-devel-list at lists.ximian.com
> > > Subject: [Mono-devel-list] DateTime Parameters in MSSQL Server
> > >
> > > I've an issue with datetime parameters with MSSQL Server in Mono...
> > > It seem's that the parameters is badly sent to the SQL Server...
> > > Please test that :
> > >
> > > using System;
> > > using System.Data;
> > > using System.Data.SqlClient;
> > >
> > > class MainClass
> > > {
> > > 	static string cnx="user id=sa;password=sa;data
> > > source=10.69.100.93;initial
> > > catalog=Fiche_Produit";
> > >
> > >
> > > 	public static void Main(string[] args)
> > > 	{
> > > 		Console.WriteLine("Hello World!");
> > > 		SqlCommand cmd=new SqlCommand();
> > > 		cmd.Connection=new SqlConnection(cnx);
> > > 		cmd.CommandText="INSERT INTO essais (date) VALUES (@date)";
> > > 		cmd.Parameters.Clear();
> > >
> > > 	cmd.Parameters.Add("@date",SqlDbType.DateTime).Value=DateTime.Now;
> > > 		cmd.Connection.Open();
> > > 		cmd.ExecuteNonQuery();
> > > 		cmd.Connection.Close();
> > > 	}
> > > }
> > >
> > > it returns :
> > > Unhandled Exception: System.Data.SqlClient.SqlException: Erreur de
> > > conversion
> > > du type de données varchar en datetime.
> > > Erreur de conversion du type de données varchar en datetime.
> > > in [0x00034]
> > > (at
> > > /home/hubert/mono/mcs/class/System.Data/System.Data.SqlClient/SqlConnec
> > >ti o n.cs:266)
> > > System.Data.SqlClient.SqlConnection:ErrorHandler (System.Object sender,
> > > Mono.Data.Tds.Protocol.TdsInternalErrorMessageEventArgs e)
> > > in (wrapper delegate-invoke)
> > > System.MulticastDelegate:invoke_void_object_TdsInternalErrorMessageEven
> > >tA r gs
> > > (object,Mono.Data.Tds.Protocol.TdsInternalErrorMessageEventArgs)
> > >
> > >
> > > In english : error when converting a varchar datatype into a datetime
> > >
> > > thanks
> > >
> > > _______________________________________________
> > > Ce message et les éventuels documents joints peuvent contenir des
> > > informations confidentielles.
> > > Au cas où il ne vous serait pas destiné, nous vous remercions de bien
> > > vouloir le supprimer et en aviser immédiatement l'expéditeur. Toute
> > > utilisation de ce message non conforme à sa destination, toute
> > > diffusion ou publication, totale ou partielle et quel qu'en soit le
> > > moyen est formellement interdite.
> > > Les communications sur internet n'étant pas sécurisées, l'intégrité de
> > > ce message n'est pas assurée et la société émettrice ne peut être tenue
> > > pour responsable de son contenu.
> > > _______________________________________________
> > > Mono-devel-list mailing list
> > > Mono-devel-list at lists.ximian.com
> > > http://lists.ximian.com/mailman/listinfo/mono-devel-list
> >
> > _______________________________________________
> > Mono-devel-list mailing list
> > Mono-devel-list at lists.ximian.com
> > http://lists.ximian.com/mailman/listinfo/mono-devel-list
>
> _______________________________________________
> Ce message et les éventuels documents joints peuvent contenir des
> informations confidentielles. Au cas où il ne vous serait pas destiné, nous
> vous remercions de bien vouloir le supprimer et en aviser immédiatement
> l'expéditeur. Toute utilisation de ce message non conforme à sa
> destination, toute diffusion ou publication, totale ou partielle et quel
> qu'en soit le moyen est formellement interdite. Les communications sur
> internet n'étant pas sécurisées, l'intégrité de ce message n'est pas
> assurée et la société émettrice ne peut être tenue pour responsable de son
> contenu. _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list

_______________________________________________
Ce message et les éventuels documents joints peuvent contenir des informations confidentielles.
Au cas où il ne vous serait pas destiné, nous vous remercions de bien vouloir le supprimer et en aviser immédiatement l'expéditeur. Toute utilisation de ce message non conforme à sa destination, toute diffusion ou publication, totale ou partielle et quel qu'en soit le moyen est formellement interdite.
Les communications sur internet n'étant pas sécurisées, l'intégrité de ce message n'est pas assurée et la société émettrice ne peut être tenue pour responsable de son contenu.



More information about the Mono-devel-list mailing list