我需要连接到Informix,但似乎容易完成的任务变得有些烦人。 我下载了客户端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对象时,它将引发异常。它显示“无法加载DLL'iclit09b.dll'”。
根据IBM,可能的原因是必须将INFORMIXDIR和PATH设置为环境变量。但是他们并不清楚要设置什么...
我们将不胜感激。
答案 0 :(得分:3)
此旧技术说明提供了有关如何配置Windows客户端(包括PATH和INFORMIXDIR环境变量的必需值)的简单指南