Problems with .Net 2 provider
Posted in 2011
Topics: Connectivity: ODBC / JDBC / .NET
I'm not sure if I have the right place, but here goes. We are porting a mature .Net application to Informix, using the providers provided in the CSDK. Using the IBM Informix documentation as our guidance, we are having seemingly intractable problems with parametrised INSERT commands, specifically with TEXT columns: 1. The only form of parametrisation I can get to work at all is positional parameters (see below* for explanation why the others don't help). 2. Positional parameters do work with a TEXT column if it is the first parameter in the collection. But if is second or later, an error is thrown - the error message is ERROR [HY000] [Informix .NET provider][Informix]Illegal attempt to convert Text/Byte blob type.. If the TEXT parameter is the first in the parameter collection, it is fine and the command executes successfully! Are we (a) doing something stupid, or (b) is there a problem with parametrised commands in the Informix .Net 2.0 provider, or (c) is the IBM documentation simply wrong or incomplete? We are using the 11.7 client tools, which is the latest version, I believe. More importantly, does anyone know how to get around this? Parametrised commands are more or less essential. TIA Neil. (*Explanation: - I can't enable Host Variables (:parameter) in the IDS server because the Ifxconnectionstringbuilder will not accept "HostVarParameters=TRUE" in the connection string: it's not available as a key in the dictionary. Nor will IDS allow it if I try to connect to the server instance using a literal connection string variable. - Using named parameters (@parameter) gives a syntax error whrn the command ExecuteNonQuery() is called. A commandtext of "insert into sometable (col1) values (@col1)" with a parametercollection of (Name=@col1, value= someValue) gives a syntax error. Ditto with a parametercollection of (Name=col1, value= someValue) )
Ok, we've distilled the code down to a very simple fragment, as per the IBM Informix developer's Handbook (Red Book): using (IDbConnection cn = new IfxConnection()) { cn.ConnectionString = IDSInstanceStr; cn.Open(); try { Dictionary<string, string> columns = new Dictionary<string, string>(); columns.Add("field1", "integer"); columns.Add("field3", "text"); columns.Add("field2", "smallint"); CreateTable(cn, testTableName, columns); using (IDbCommand cmd = cn.CreateCommand()) { var param1 = new IfxParameter("field1", DbType.Int32); param1.Value = 1; cmd.Parameters.Add(param1); var param2 = new IfxParameter("field3", DbType.String); param2.Value = "a simple note"; cmd.Parameters.Add(param2); var param3 = new IfxParameter("field2", DbType.Int16); param3.Value = 0; cmd.Parameters.Add(param3); cmd.CommandType = CommandType.Text; cmd.CommandText = string.Format("insert into {0} (field1, field3, field2) values (?,?,?)", testTableName); cmd.ExecuteNonQuery(); } } finally { DropTable(cn, testTableName); } } This results in an Informix error: IBM.Data.Informix.IfxException: ERROR [HY000] [Informix .NET provider][Informix]Illegal attempt to convert Text/Byte blob type.. BUT if we replace the cmd.CommandText line with an explicit nonparameterised command, eg cmd.CommandText = string.Format("insert into {0} (field1, field3, field2) values (1, 'a simple note', 0)", testTableName); the line is inserted with no drama. Equally, if the text parameter is the first one added to the parameter collection the command executes successfully. So it appears that there is a problem with parameterised commands, specifically with TEXT parameters UNLESS the text column is the first parameter in the collection. Has anyone else experienced this issue? Is it a bug in the Informix .Net provider, or have we missed something? (I ought to add that this code works perfectly well with Oracle and MS SqlServer). Most importantly, how can we get around it? Parametrised commands are imperative for this application. TIA Neil.