非常奇怪的 iSeries Provider 行为
我们的 RPG 人员给了我们一个“存储过程”,它返回六个数据表。尝试使用 iSeries Provider for .NET(尝试使用 V5R4 和 V6R1)从 .NET(C#、3.5)调用它,我们根据调用存储过程的方式看到不同的结果。我们更喜欢这样做:
using (var dbConnection = new iDB2Connection("connectionString"))
{
dbConnection.Open();
using(var cmd = dbConnection.CreateCommand())
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "StoredProcName";
cmd.Parameters.Add(new iDB2Parameter("InParm1",
iDB2DbType.Varchar).Value = thing;
var ds = new DataSet();
var da = new iDB2DataAdapter(cmd);
da.Fill(ds);
}
}
这样做,我们会在结果集中返回 5 个表。但是,如果我们这样做:
cmd.CommandType = CommandType.Text;
cmd.CommandText = "CALL StoredProcName('" + thing + "')";
我们会返回预期的 SIX 个表。
我意识到这里没有多少人对 .NET 到 DB2 感到抱歉,但我希望以前有人看到过这一点。
TIA。
We've been given a "stored procedure" from our RPG folks that returns six data tables. Attempting to call it from .NET (C#, 3.5) using the iSeries Provider for .NET (tried using both V5R4 and V6R1), we are seeing different results based on how we call the stored proc. Here's way that we'd prefer to do it:
using (var dbConnection = new iDB2Connection("connectionString"))
{
dbConnection.Open();
using(var cmd = dbConnection.CreateCommand())
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "StoredProcName";
cmd.Parameters.Add(new iDB2Parameter("InParm1",
iDB2DbType.Varchar).Value = thing;
var ds = new DataSet();
var da = new iDB2DataAdapter(cmd);
da.Fill(ds);
}
}
Doing it this way, we get FIVE tables back in the result set. However, if we do this:
cmd.CommandType = CommandType.Text;
cmd.CommandText = "CALL StoredProcName('" + thing + "')";
We get back the expected SIX tables.
I realize that there aren't many of us sorry .NET-to-DB2 folks out here, but I'm hoping someone has seen this before.
TIA.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看连接字符串的 LibraryList(也许还有命名)属性。当您使用 CommandType.StoredProcedure 时,它可以直接从 SQL 数据库执行存储过程。当您使用 CommandType.Text 时,它会搜索库列表以查找存储过程。您最终会从不同的库运行不同版本的存储过程,这会产生不同的结果。
Look into the LibraryList (and maybe the Naming) property of your connection string. When you use CommandType.StoredProcedure it could be executing the stored procedure right from the SQL database library. When you use CommandType.Text it searches the library list to find the stored procedure. You end up running different versions of the stored procedure from different libraries which gives you different results.