【问题标题】:Unable to connect on Linux to Informix database with Mono无法在 Linux 上使用 Mono 连接到 Informix 数据库
【发布时间】:2011-03-22 10:39:43
【问题描述】:

我正在尝试使用 Mono 访问 Informix (IDS 11.7) 数据库 在 Linux 上(Centos 5.4)

我可以使用下面的小程序访问一个mysql数据库没有问题。 我可以毫无问题地“isql unicare”,所以看来 unixODBC 还可以。

这些是我的 odbc.ini 和 odbcinst.ini 文件(使用 Adam Williams 提供的建议
致 Nick Gorham,地址为 http://www.unixodbc.org/doc/informix.html

/etc/odbc.ini

[MyDSN]
DRIVER=/usr/lib/libmyodbc3.so  
SERVER=localhost  
DATABASE=unicare  
UID=root  
PWD=MyWord  
PORT=

[unicare]  
Driver=Informix  
Server=unicare  
Database=unicare  
CLIENT_LOCALE=en_us.8859-1  
DB_LOCALE=en_us.8859-1  
TRANSLATIONDLL=/u/Informix11_7/lib/esql/igo4a304.so  

/etc/odbcinst.ini

##-Example driver definitinions  
##-Included in the unixODBC package  
[PostgreSQL]  
Description     = ODBC for PostgreSQL  
Driver          = /usr/lib/libodbcpsql.so  
Setup           = /usr/lib/libodbcpsqlS.so  
FileUsage       = 1  

# Driver from the MyODBC package  
# Setup from the unixODBC package  
[MySQL]  
Description     = ODBC for MySQL  
Driver          = /usr/lib/libmyodbc.so  
Setup           = /usr/lib/libodbcmyS.so  
FileUsage       = 1  


[Informix]  
Description=Informix IDS 11.7  
Driver=/u/Informix11_7/lib/cli/libifcli.so  
##Driver=/u/Informix11_7/lib/cli/iclit09b.so  
APILevel=1  
ConnectFunctions=YYY  
DriverODBCVer=03.51  
FileUsage=0  
SQLLevel=1  
smProcessPerConnect=Y  

这是http://mono-project.com/ODBC上的示例程序, 我在 MySQL 数据库上成功使用了原版,然后 更改为此以匹配 Informix 数据库的 DSN。

同样,“isql unicare”工作并读取 Informix 数据库的员工表。 如果脚本看起来很糟糕,我很抱歉,但我在这里与编辑作斗争!

TestExample.cs

using System;
using System.Data;
using System.Data.Odbc;

 public class Test
 {
    public static void Main(string[] args)
    {
                // have an ODBC DSN setup named MYSQLDSN
                // that accesses a MySQL database via
                // MyODBC driver for ODBC with a
                // hostname of localhost and database test
       string connectionString =
          "DSN=unicare;" +
          "UID=bob;" +
          "PWD=BobWord";
       IDbConnection dbcon;
       dbcon = new OdbcConnection(connectionString);
       dbcon.Open();
       IDbCommand dbcmd = dbcon.CreateCommand();
       // requires a table to be created named employee
       // with columns firstname and lastname
       // such as,
       //        CREATE TABLE employee (
       //           firstname varchar(32),
       //           lastname varchar(32));
       string sql =
           "SELECT firstname, lastname " +
           "FROM employee";
       dbcmd.CommandText = sql;
       IDataReader reader = dbcmd.ExecuteReader();
       while(reader.Read()) {
            string FirstName = (string) reader["firstname"];
            string LastName = (string) reader["lastname"];
            Console.WriteLine("Name: " +
                FirstName + " " + LastName);
       }
       // clean up
       reader.Close();
       reader = null;
       dbcmd.Dispose();
       dbcmd = null;
       dbcon.Close();
       dbcon = null;
    }
 }

但是当我运行它时,我得到...

$ mono TestExample.exe

Unhandled Exception: System.Data.Odbc.OdbcException: ERROR [I

我应该使用 Informix 的 odbc.ini 和 odbcinst.ini(已编辑)吗?

如果我使用更常规的 odbc*ini 集,那么我会得到更详细的信息 错误消息未处理的异常:System.Data.Odbc.OdbcException: ERROR [IM002] [unixODBC][Driver Manager]Data source name not found, 并且没有指定默认驱动程序 at System.Data.Odbc.OdbcConnection.Open () [0x00000] in <filename unknown>:0

我怀疑我收到的这条乱码信息是这样的; 据报道 http://article.gmane.org/gmane.comp.gnome.mono.general/35093

任何想法或帮助将不胜感激。

【问题讨论】:

    标签: odbc informix


    【解决方案1】:

    您需要将odbc.ini 中的“驱动程序”指向共享库文件,就像您对“MyDSN”条目所做的那样。这是我使用的 - 效果很好:

    [tsdemo]
    Driver=/opt/IBM/informix/lib/cli/iclit09b.so
    Description=IBM INFORMIX ODBC DRIVER
    Database=tsdemo
    LogonID=informix
    pwd=inf123
    Servername=storm_tcp
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多