Driver problems when reading Blobs
Posted in 2003
We have a .NET application that writes and reads a particular table with a TEXT blob (containing an XML document) in it using Informix OLEDB drivers. When using version 2.70.TC1, the BLOB writes and reads just fine. However, when using version 2.80 or 2.81, the BLOB will write fine, but when you read it back with the newer drivers you get binary garbage (regardless of which version it was written with). I've included the definition and code below in case it is a coding issue and so you can see what we're doing. This is against a 9.30.UC1 database. We would like to use the newer drivers to take advantage of some other features there but can't because of this issue. Any suggestions/ideas? Have any of you seen this problem? Here is the code: Here's the table definition in the Informix database: <<...OLE_Obj...>> Here's the logic that writes an entry to the plink_log table (including the xml_doc column). This logic works when using 2.70.TC1, 2.80, and 2.81 drivers. public void WriteLogMsg(string indicator, string xmlType, string msg) { // This method will insert an entry into the plink_log table // indicator: S=Send, R=Receive, E=Exception, T=Translate // xmlType: 1=signon, 2=signon response, 3=acct_open_update_request, // 4=acct_open_update_response, 5=error, 6=other (exception) // 7=PONA+ XML request, 8=PershingLink XML response // msg: the message or xml data to write to the log table string mySql; try { OleDbConnection myConnection = new OleDbConnection(SqlSession); mySql = "INSERT INTO plink_log ( trans_id, " + " pershing_num, " + " send_recv_excp_ind, " + " trans_datetime, " + " rep_num, " + " bd_num, " + " xml_type ) " + " VALUES(0, '" + pershingNumber + "', " + "'" + indicator + "', current, '" + repNumber + "', " + bdNumber.ToString() + ", '" + xmlType + "')"; // MessageBox.Show(mySql); OleDbCommand myCommand = new OleDbCommand(mySql, myConnection); myCommand.Connection.Open(); myCommand.ExecuteNonQuery(); // Now get the serial field just created in order to update the // xml_doc BLOB field with the msg mySql = "SELECT max(trans_id) FROM plink_log" + " WHERE pershing_num = '" + pershingNumber + "' AND xml_type = '" + xmlType + "'"; OleDbCommand myCommand2 = new OleDbCommand(mySql, myConnection); OleDbDataReader myOleDbReader = myCommand2.ExecuteReader(); myOleDbReader.Read(); int myTransId = myOleDbReader.GetInt32(0); myOleDbReader.Close(); // MessageBox.Show("Got transaction ID: " + myTransId.ToString()); // Now update the BLOB field with the msg mySql = "UPDATE plink_log SET xml_doc=? WHERE trans_id = " + myTransId.ToString(); OleDbCommand myCommand3 = new OleDbCommand(mySql, myConnection); OleDbParameter P = new OleDbParameter ("@xml_doc", OleDbType.LongVarChar, msg.Length - 5, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, msg); myCommand3.Parameters.Add(P); myCommand3.ExecuteNonQuery(); myConnection.Close(); } catch //(Exception e) { // ignore any exceptions while writing log // MessageBox.Show("Got an exception: " + e.ToString()); } } Here's the ASP.Net C# logic that reads an entry from the xml_doc column. This logic works ONLY when using the 2.70.TC1 driver. string mySql, s = ""; try { mySql = "SELECT xml_doc FROM plink_log" + " WHERE trans_id = " + Request.QueryString["id"]; OleDbDataAdapter myCommand = new OleDbDataAdapter(mySql,myConnection); DataSet ds = new DataSet(); myCommand.Fill(ds, "Table"); foreach (DataRow myDataRow in ds.Tables["Table"].Rows) { s = myDataRow["xml_doc"].ToString(); } myCommand.Dispose(); myConnection.Close(); Response.Output.Write(s); } catch { return; } When using the 2.80 or 2.81 drivers, the result in s is garbaged binary-like data. Under the 2.70 TC1 driver, the data in s readable string formatted data. Bill Weaver, Development Manager IS, ext. 6525 Advantage Capital Corporation FSC Securities Corporation 2300 Windy Ridge Parkway Suite 1100 Atlanta, GA 30339 800-547-2382 770-916-6525 bweaver@fscorp.com <mailto:bweaver@fscorp.com> www.aigadvisorgroup.com<http://www.aigadvisorgroup.com/> Securities and investment advisory services offered through Advantage Capital Corporation and FSC Securities Corporation, members NASD, SIPC and SEC-Registered Investment Advisers. AIG Advisor Group is the marketing designation for the wholly owned subsidiary broker-dealer members of AIG. This message and any attachments contain information from AIG Advisor Group, which may be confidential and/or privileged and is intended for use only by the addressee(s) named on this transmission. If you are not the intended recipient, or the employee or agent responsible for delivering the message to the intended recipient, you are notified that any review, copying, distribution or use of this transmission is strictly prohibited. If you have received this transmission in error, please (i) notify the sender immediately by e-mail or by telephone and (ii) destroy all copies of this message. sending to informix-list