无法从 ODBC 连接检索数据到 DB2 iSeries
我已经尝试连接到 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定到底是什么问题,但是您可以尝试使用数据读取器,看看是否会带来更好的结果?
其次,您确定您的查询会在合理的时间内返回吗?您是否有一些工具可以让您直接对数据库运行查询(我不熟悉 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?
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
在连接字符串中将 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.
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