IfxDataReader返回null

时间:2015-03-24 10:30:45

标签: c# .net informix

当我尝试使用C#在informix上执行查询时,它会给我这个错误{"Object reference not set to an instance of an object."}

我正在使用:

  • Windows 7 Ultimate 64bits
  • VS2013 Ultimate
  • Informix Client SDK3.50.FC9.WIN

这是我的代码;

string ConnectionString = "Blah;" + "Service=sqlexec;" + "Server=Blah;" + "Database=base004;" + "Uid=me;" + "Pwd=pw;";
IfxConnection conn = new IfxConnection(ConnectionString);
conn.ConnectionString = ConnectionString;
try
{
   string resql = "select * from table";                  
   try
   {
       conn.Open();
       MessageBox.Show("Connection open");
       IfxCommand rq = new IfxCommand(resql, conn);
       IfxDataReader dr = rq.ExecuteReader();
       while (dr.Read()) 
       {
           string a = dr.GetString(0);
           int b = dr.GetInt32(1);
           string c = dr.GetString(2);
       }
    }
    catch (IfxException ex)
    {
        MessageBox.Show(ex.Message);
    }
    conn.Close();
}
catch (IfxException ex)
{
    MessageBox.Show(ex.Message);
}

1 个答案:

答案 0 :(得分:1)

所以问题,我想,是框架的版本。我降级到2.0 .net框架并且它起作用了。我已经在两台服务器上试过了,很好! 我也改变了我从3.5到4.1的CSDK

@MarcGravell谢谢你!