无法在 Linux 上使用 Mono 连接到 Informix 数据库

发布于 2024-10-25 17:03:03 字数 4110 浏览 6 评论 0原文

我正在尝试使用 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: 错误 [IM002] [unixODBC][驱动程序管理器]未找到数据源名称, 并且没有指定默认驱动程序 在 <文件名未知> 中的 System.Data.Odbc.OdbcConnection.Open () [0x00000]:0

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

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

I am trying to use Mono to access an Informix (IDS 11.7) database
on Linux (Centos 5.4)

I can access a mysql database using the small program below with no problems.
I can "isql unicare" with no problem, so it seems the unixODBC is OK.

These are my odbc.ini and odbcinst.ini files (using suggestions supplied by Adam Williams
to Nick Gorham found at 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  

Here is the sample program found on http://mono-project.com/ODBC,
where I have used the original successfully on a MySQL database, and then
changed to this to match the DSN of the Informix database.

Again, "isql unicare" works and reads the employee table of the Informix database.
Apologies if the script looks nasty, but I am battling with the editor here!

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;
    }
 }

But when I run it, I get ...

$ mono TestExample.exe

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

Should I use the odbc.ini and odbcinst.ini (edited) from Informix?

If I use a more regular looking odbc*ini set then I get a more verbose
errror message Unhandled Exception: System.Data.Odbc.OdbcException:
ERROR [IM002] [unixODBC][Driver Manager]Data source name not found,
and no default driver specified
at System.Data.Odbc.OdbcConnection.Open () [0x00000] in <filename unknown>:0

and I am suspicious that this garbled message that I am getting is this;
as reported on
http://article.gmane.org/gmane.comp.gnome.mono.general/35093

Any ideas or help would be greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧人 2024-11-01 17:03:03

您需要将 odbc.ini 中的“Driver”指向共享库文件,就像“MyDSN”条目一样。这是我使用的 - 它运行完美:

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

You need to point 'Driver' in odbc.ini to the shared library file, as you have for the 'MyDSN' entry. Here's what I use - it works perfectly:

[tsdemo]
Driver=/opt/IBM/informix/lib/cli/iclit09b.so
Description=IBM INFORMIX ODBC DRIVER
Database=tsdemo
LogonID=informix
pwd=inf123
Servername=storm_tcp
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文