无法从 ODBC 连接检索数据到 DB2 iSeries

发布于 2024-11-24 09:08:14 字数 865 浏览 1 评论 0原文

我已经尝试连接到 AS/400 上的 DB2 数据库好几天了!安装 IBM System i Access for Windows 客户端后,我可以从 Visual Studio 创建 ODBC 数据源,当我单击“测试连接”时,它就成功了。但是,执行简单的 SELECT 语句会导致无限等待,因为数据库似乎没有响应它。 我用来连接和查询的代码是:

            OdbcConnection conn = new OdbcConnection(@"Dsn=TEST1;Uid=myuser;Pwd=mypwd;DBQ=mydb2");
            conn.Open(); 

            try
            {
                string cmmTxt = query;
                OdbcCommand cmd = new OdbcCommand(cmmTxt, conn);
                OdbcDataAdapter da = new OdbcDataAdapter(cmd);
                da.Fill(dset);
            }
            catch (Exception e)
            {
                Console.Write(e.StackTrace);
            }
            finally
            {
                conn.Close();
            }

执行停止响应的行是“da.Fill(dset);”。顺便说一句,我使用的是 Visual Studio 2010,没有看到任何错误消息,但代码在该行之后永远不会完成“等待”。你有什么想法吗?提前致谢

I've been trying to connect to a DB2 database on AS/400 for days! After I installed the IBM System i Access for Windows client I could create an ODBC data source from visual studio and when I click on "test connection" it is sucessful. However, executing a simple SELECT statement results in an infinite wait since database doesn't seem to respond to it.
The code I'm using to connect and query is:

            OdbcConnection conn = new OdbcConnection(@"Dsn=TEST1;Uid=myuser;Pwd=mypwd;DBQ=mydb2");
            conn.Open(); 

            try
            {
                string cmmTxt = query;
                OdbcCommand cmd = new OdbcCommand(cmmTxt, conn);
                OdbcDataAdapter da = new OdbcDataAdapter(cmd);
                da.Fill(dset);
            }
            catch (Exception e)
            {
                Console.Write(e.StackTrace);
            }
            finally
            {
                conn.Close();
            }

The line where the execution stops responding is "da.Fill(dset);". BTW I'm using visual studio 2010 and I don't see any error message, but the code never finishes "waiting" after that line. Do you have any ideas? Thanks in advance

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

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

发布评论

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

评论(2

一花一树开 2024-12-01 09:08:14

我不确定到底是什么问题,但是您可以尝试使用数据读取器,看看是否会带来更好的结果?

OdbcConnection conn = new OdbcConnection(@"Dsn=TEST1;Uid=myuser;Pwd=mypwd;DBQ=mydb2");
string SQL = "SELECT COUNT(*) FROM MyTable";
using (OdbcCommand com = new OdbcCommand(SQL, connection, null))
{
    using (OdbcDataReader reader = com.ExecuteReader())
    {
        while (reader.Read())
        {
            var value = reader["MyColumn"];
        }
    }
}

其次,您确定您的查询会在合理的时间内返回吗?您是否有一些工具可以让您直接对数据库运行查询(我不熟悉 DB2,不确定是否有这样的东西)。或者是否有一个“分析器”可以让您在数据库查询进入时“查看”它们?

由于您没有显示查询,我想知道这是否是一个运行时间非常长的查询。您等待查询返回多久了?

约翰

I'm not sure exactly what the problem is, but can you try using a data reader and see if that gives you better results?

OdbcConnection conn = new OdbcConnection(@"Dsn=TEST1;Uid=myuser;Pwd=mypwd;DBQ=mydb2");
string SQL = "SELECT COUNT(*) FROM MyTable";
using (OdbcCommand com = new OdbcCommand(SQL, connection, null))
{
    using (OdbcDataReader reader = com.ExecuteReader())
    {
        while (reader.Read())
        {
            var value = reader["MyColumn"];
        }
    }
}

Second, are you sure that your query will return in a reasonable amount of time? Do you have some tool which lets you run queries directly against the database (I'm not familiar with DB2, not sure if there is such a thing). Or is there a "profiler" that lets you "peek" at the database queries as they come in?

Since you don't show your query, I wonder if it's a very long-running query. How long did you wait for the query to return?

John

じ违心 2024-12-01 09:08:14

在连接字符串中将 LONGDATACOMPAT 标志设置为 1 对我有用。

[C#]
OdbcConnection con =
  new OdbcConnection("DSN=SAMPLE;UID=uid;PWD=mypwd;
  LONGDATACOMPAT=1;");

请参阅以下 URL 中的完整说明

http://pic.dhe.ibm.com/infocenter/db2luw/v9r7/index.jsp?topic=%2Fcom.ibm.swg.im.dbclient.adonet.doc%2Fdoc%2Fr0011829.html

Setting LONGDATACOMPAT flag as 1 in the connection string worked for me.

[C#]
OdbcConnection con =
  new OdbcConnection("DSN=SAMPLE;UID=uid;PWD=mypwd;
  LONGDATACOMPAT=1;");

see the full explanation in the URL below

http://pic.dhe.ibm.com/infocenter/db2luw/v9r7/index.jsp?topic=%2Fcom.ibm.swg.im.dbclient.adonet.doc%2Fdoc%2Fr0011829.html

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