从代码更改/创建 ODBC 连接

发布于 2024-10-09 06:20:35 字数 552 浏览 7 评论 0原文

我正在通过 ODBC 连接从 C# ASP .Net 4.0 使用 Informix DB。该数据库确实经常更改,因此我从 sysmaster 表中读取了安装的数据库。

根据我的用户所做的选择,我需要设置与所选数据库的 ODBC 连接,或更改当前连接以从 systmaster 数据库更改为所选数据库。

有人知道如何做到这一点吗?我怀疑必须可以设置临时 ODBC 连接。另外,在 Visual Studio 中,在 ODBC 连接的属性下,我确实有一个如下所示的连接字符串:

Dsn=Informix;uid=xxxxx;database=sysmaster;host=10.10.10.10;srvr=testdb1;serv=3000;pro=onsoctcp;cloc=en_US.819;dloc=en_US.819;vmb=0;curb=0;scur=0;icur=0;oac=1;optofc=0;rkc=0;odtyp=0;ddfp=0;dnl=0;rcwc=0

我四处寻找无需 ODBC 即可直接连接到 informix 的库,但现在成功了。

谢谢, 斯特凡

I'm working against a Informix DB from C# ASP .Net 4.0 via an ODBC connection. This database does change frequently so I read out what DBs that are installed from the sysmaster table.

Depending on choice my user makes I need to setup a ODBC connection to the choosen DB or change the current connection to change from the systmaster DB to the one choosen.

Anyone got any idea how to do this? I suspect it must be possible to setup a temporary ODBC connection. Also in Visual Studio under the properties for my ODBC connection I do have a connection string looking like this:

Dsn=Informix;uid=xxxxx;database=sysmaster;host=10.10.10.10;srvr=testdb1;serv=3000;pro=onsoctcp;cloc=en_US.819;dloc=en_US.819;vmb=0;curb=0;scur=0;icur=0;oac=1;optofc=0;rkc=0;odtyp=0;ddfp=0;dnl=0;rcwc=0

I have looked around for a library to connect directly without the ODBC to informix but with now success.

Thanks,
Stefan

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

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

发布评论

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

评论(2

-柠檬树下少年和吉他 2024-10-16 06:20:35

我已经制定了一个非常好的工作解决方案。我没有意识到 .NET 完全支持从代码隐藏中执行此操作,而无需实际修改 ODBC 设置。

    const string sConnString = "Driver=Informix;uid=user;pwd=password;database=x10stg01_1312;host=10.10.10.10;srvr=testdb1;serv=3000;pro=onsoctcp;cloc=en_US.819;dloc=en_US.819;vmb=0;curb=0;scur=0;icur=0;oac=1;optofc=0;rkc=0;odtyp=0;ddfp=0;dnl=0;rcwc=0";
    var oOdbcConnection = new System.Data.Odbc.OdbcConnection(sConnString);

    string queryString =
        "SELECT * FROM tevoc WHERE ev_oc_id=6599098";
    OdbcCommand command = new OdbcCommand(queryString);

    command.Connection = oOdbcConnection;
    oOdbcConnection.Open();
    OdbcDataReader odbcDataReader = command.ExecuteReader();

    while (odbcDataReader.Read())
    {
        CheckDiv.InnerHtml += "Result: " + odbcDataReader.GetString(6) + "<br/>";
    }

我想您必须在尝试后面的代码之前设置一个有效的 ODBC 连接,以确保驱动程序可以正常定位或至少查看可用的 ODBC 驱动程序列表。

I have worked out a working solution that is quite nice. I did not realise .NET had full support to do this from code behind without actually modifying the ODBC settings.

    const string sConnString = "Driver=Informix;uid=user;pwd=password;database=x10stg01_1312;host=10.10.10.10;srvr=testdb1;serv=3000;pro=onsoctcp;cloc=en_US.819;dloc=en_US.819;vmb=0;curb=0;scur=0;icur=0;oac=1;optofc=0;rkc=0;odtyp=0;ddfp=0;dnl=0;rcwc=0";
    var oOdbcConnection = new System.Data.Odbc.OdbcConnection(sConnString);

    string queryString =
        "SELECT * FROM tevoc WHERE ev_oc_id=6599098";
    OdbcCommand command = new OdbcCommand(queryString);

    command.Connection = oOdbcConnection;
    oOdbcConnection.Open();
    OdbcDataReader odbcDataReader = command.ExecuteReader();

    while (odbcDataReader.Read())
    {
        CheckDiv.InnerHtml += "Result: " + odbcDataReader.GetString(6) + "<br/>";
    }

I guess you have to setup a working ODBC connection one before trying the code behind to just be sure the Driver can be located ok or at least look in the list of available ODBC drivers.

感情旳空白 2024-10-16 06:20:35

我想您可以直接修改注册表,但您也可以调用 odbcconf.exe,这是一个标准的 Windows 实用程序。 是一个 MSDN 链接

这 在研究如何操作 ODBC 连接时,我做了如下操作来添加连接:

odbcconf.exe /a {CONFIGSYSDSN "SQL Server" "DSN=?|Description=?|SERVER=?(local)|Trusted_Connection=no|Database=?"}

当然,您可以用自己的参数替换 ?

I suppose you could mess with the registry directly, but you could also call odbcconf.exe, which is a standard Windows utility. Here's an MSDN link

Back when I was looking into how to manipulate ODBC connections, I did something like the following to add a connection:

odbcconf.exe /a {CONFIGSYSDSN "SQL Server" "DSN=?|Description=?|SERVER=?(local)|Trusted_Connection=no|Database=?"}

Of course, you'd replace the ? with your own parameters.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文