Wednesday, August 25, 2010

C# and mySQL error: Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)


Problem:
When working with C# and mySQL, I use the code below I get the error message "Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)"


       public DataSet ExecuteQuery(System.Data.Common.DbTransaction trans, CommandType cmdType, string cmdText,
           params System.Data.Common.DbParameter[] cmdParms)
       {
           MySqlCommand cmd = new MySqlCommand();

           PrepareCommand(cmd, trans.Connection, trans, cmdType, cmdText, cmdParms);

           MySqlDataAdapter da = new MySqlDataAdapter(cmd);

           DataSet ds = new DataSet();

           da.Fill(ds, "ds");

           cmd.Parameters.Clear();

           return ds;
       }


Cause:
The problem is that the the guids are being returned as varbinary(16) instead of binary(16) and as a result nhibernate throws an error.

Solution:
After version 6.1.1 you should add "old guids=true" to your connection string whenever you use BINARY(16) as your storage type. Else you should use CHAR(36)




3 comments: