gpt4 book ai didi

c# - 通过 C# 连接到 Informix

转载 作者:太空宇宙 更新时间:2023-11-03 22:43:29 25 4
gpt4 key购买 nike

我需要连接到 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 对象时抛出异常。它说“无法加载 DLL 'iclit09b.dll'”。

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

我们将不胜感激。

最佳答案

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

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

关于c# - 通过 C# 连接到 Informix,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51042747/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com