64位操作系统中用C#连接Informix

测试环境:Windows2008+SQL2008R2+Linux虚拟机+Informix9数据库+IBM INFORMIX-Client SDK 3.70.FC4

连接步骤:

一、开启Linux虚拟机,启动网络配置,启动Informix数据库

二、安装Windows下的Informix数据库客户端工具IBM INFORMIX-Client SDK 3.70.FC4,配置好下面两个跟你的Informix数据库相关的配置

1、用记事本打开C:\Windows\System32\drivers\etc\hosts文件,在末尾添加

127.0.0.1       localhost
Informix_Server_IP Informix_Server_Name

其中Informix_Server_IP是Linux服务器的IP地址如192.168.1.100格式;Informix_Server_Name是Linux服务器的名字

 

2、用记事本打开C:\Windows\System32\drivers\etc\hosts文件,在末尾添加

Informix_Service_Name        Informix_Server_Port/tcp                    #Remote Linux Informix Data Server

其中Informix_Service_Name是Linux服务器的服务名称如sqlinformix格式;Informix_Server_Port是Linux服务器的Informix数据库端口数字如8000.

 

三、点击“开始-〉运行-〉输入C:\Windows\SysWOW64\odbcad32.exe”,打开64位ODBC数据源管理器

四、添加自定义到Informix数据库的配置

1、点击用户DSN窗体中的添加按钮,打开创建新数据源窗体,在驱动程序列表中选择“IBM INFORMIX ODBC DRIVER”.点“完成”按钮。打开“IBM Informix ODBC Driver Setup”界面。

2、在“IBM Informix ODBC Driver Setup”界面中的General窗体中填写自定义的DSN名称如“TestInformixDSN”.

3、在“IBM Informix ODBC Driver Setup”界面中的Connection窗体中填写自定义的Server Name名称如“Informix_Server_Name”.

4、在“IBM Informix ODBC Driver Setup”界面中的Connection窗体中填写自定义的Host Name名称如“Informix_Server_IP”.

5、在“IBM Informix ODBC Driver Setup”界面中的Connection窗体中填写自定义的Service名称如“Informix_Service_Name”.

6、在“IBM Informix ODBC Driver Setup”界面中的Connection窗体中选择Protocol名称如“onsoctcp”.

7、在“IBM Informix ODBC Driver Setup”界面中的Connection窗体中填写自定义的Database Name名称如“informix_dbname”.

8、在“IBM Informix ODBC Driver Setup”界面中的Connection窗体中填写自定义的User Id值如“informix”. 

9、在“IBM Informix ODBC Driver Setup”界面中的Connection窗体中填写自定义的Password值如“informix”.

上述设置完成后点Apply@Test Connection按钮。结果出现“Test connection was successful”提示的话。就表示连接成功,点击确定按钮,完成所有设置

 

打开VS2008,新建一个应用程序窗体,添加一个按钮,双击按钮后输入下面代码测试:

try
            {
                OdbcConnection conn = new OdbcConnection();
                conn.ConnectionString = “Dsn=自定义的DSN名称;Driver={INFORMIX 3.70 64 BIT};Host=Linux服务器IP地址;Server=林;Service=Linux数据库服务名称;Protocol=onsoctcp;Database=Linux中的数据库名称;Uid=Linux中的数据库用户;Pwd=Linux中的数据库密码”;
                conn.Open();

                string strSql = "select tabname from baoxiao : informix . systables  where tabid >99 and tabtype='T' order by tabname";
                OdbcDataAdapter adapter = new OdbcDataAdapter(strSql, conn);
                DataSet ds = new DataSet();
                adapter.Fill(ds, "data");
                //绑定所有表字段数据到dataGridView1
                this.dataGridView1.DataSource = null;
                this.dataGridView1.DataSource = ds.Tables[0];
                this.dataGridView1.Refresh();

                conn.Close();
                MessageBox.Show("测试通过");
            }
            catch(Exception ex)
            {
                MessageBox.Show("连接失败"+ex.Message);
            }

 

附:Informix相关软件下载地址:ftp.software.ibm.com/software/data/informix/downloads/

posted on 2012-05-22 12:02  风灵溪清  阅读(328)  评论(0编辑  收藏  举报

导航