通过 C# 连接到 Informix

Connect to Informix via C#

我需要连接到 Informix,但看似简单的任务变得有点烦人。 我下载了Client SDK并添加了对DLL的引用。

代码如下:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using IBM.Data.Informix;

namespace ConsoleApp3
{
    class Program
    {

        public static IfxConnection conn { get; set; }

        public static IfxCommand cmd { get; set; }

        /// <summary>
        /// Opens a database connection
        /// </summary>
        /// <param name="host">Set the host of the database. Ex: 192.168.0.1</param>
        /// <param name="service">Set the service number (port). Ex: 1525</param>
        /// <param name="server">Set the server name. Ex: srv</param>
        /// <param name="database">Set the database name. Ex: InformixDB</param>
        /// <param name="userID">Set the userID. Ex: informix</param>
        /// <param name="password">Set the password. Ex: P@ssw0rd</param>
        /// <returns></returns>
        public static void OpenConnection(string host, string service, string server, string database, string userID, string password)
        {
            string ConnectionString =
                "Host = " + host + "; " +
                "Service=" + service + "; " +
                "Server=" + server + "; " +
                "Database=" + database + "; " +
                "User Id=" + userID + "; " +
                "Password=" + password + "; ";

            try
            {
                conn = new IfxConnection();
                conn.ConnectionString = ConnectionString;
                conn.Open();
            }
            catch (Exception e)
            {
                var ex = new Exception(string.Format("{0} - {1}", e.Message, (e as Win32Exception).ErrorCode));
                throw ex;
            }
        }
        static void Main(string[] args)
        {
            OpenConnection("", "", "", "", "", "");

            Console.ReadKey();
        }
    }
}

我知道我没有关于 OpenConnection 方法的任何参数。在这种情况下它并不重要,因为它甚至在尝试连接之前就抛出了异常。它在创建 IfxConnection 对象时抛出异常。它说 "Unable to load DLL 'iclit09b.dll'".

根据IBM,可能的原因是必须将 INFORMIXDIR 和 PATH 设置为环境变量。但是他们并不清楚到底需要设置什么...

我们将不胜感激。

这篇旧技术说明提供了如何配置 Windows 客户端的简单指南(包括 PATH 和 INFORMIXDIR 环境变量所需的值)

http://www-01.ibm.com/support/docview.wss?uid=swg21083599