使用 IBM DB2 Connect 驱动程序在 i 系列上调用存储过程
我有一个 C# 应用程序,我试图从其中调用 ISeries 存储过程(包装 RPGLE 程序)。此 RPGLE 程序将结果集返回到我的 C# 应用程序。 当我尝试调用存储过程时,它会出错并无限期挂起。在调试模式下,我可以看到 SQL 错误消息,如帖子末尾所示。如果我使用 OleDBConnection 它工作正常,但它不适用于 DB2 Connect。
我尝试在我的页面上设置跟踪,但它没有帮助,因为页面只是挂起并且我无法查看堆栈跟踪。
在 ISeries 方面,我可以看到程序正确执行(为了测试,我在程序末尾的测试文件中写入一条记录。)
以前是否有人遇到过此错误?我将不胜感激任何帮助。
谢谢。
代码:-
DB2Connection conn1 = new DB2Connection(ConfigurationManager.ConnectionStrings ["db2IBM"].ConnectionString);
conn1.Open();
string callString5 = "PGMLIBLE.GETCONSIGNMENTS";
DB2Command cmd1 = new DB2Command(callString5, conn1);
cmd1.CommandType = CommandType.StoredProcedure;
cmd1.CommandTimeout = 5;
DB2Parameter prmCons = cmd1.Parameters.Add("prmCons", DB2Type.Char, 7);
prmCons.Direction = ParameterDirection.Input;
prmCons.Value = "JUT0016";
DB2Parameter prmCmp = cmd1.Parameters.Add("prmCmp", DB2Type.Char, 3);
prmCmp.Direction = ParameterDirection.Input;
prmCmp.Value = "DTA";
DB2Parameter prmIorE = cmd1.Parameters.Add("prmIorE", DB2Type.Char, 1);
prmIorE.Direction = ParameterDirection.Input;
prmIorE.Value = "Y";
DB2DataAdapter adp = new DB2DataAdapter(cmd1);
DataTable dt = new DataTable();
adp.Fill(dt);
// If I just execute cmd1.executeNonquery it doesn't error.
// cmd1.ExecuteNonQuery();
GridView2.DataSource = dt;
GridView2.DataBind();
conn1.Close();
conn1.Dispose();
cmd1.Dispose();
错误消息:-
ERROR [58005] [IBM][DB2.NET] SQL0902 An unexpected exception has occurred in Process: 5652 Thread 10 AppDomain: Name:aa196883-1-129406018469512609
There are no context policies.
Function: SQLExecDirectADONET (Params)
CallStack: at System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)
at System.Environment.get_StackTrace()
at IBM.Data.DB2.DB2ConnPool.HandleUnknownErrors(String strFncMsg, Exception exception, Boolean bThrow)
at IBM.Data.DB2.DB2Command.ExecuteReaderObject(CommandBehavior behavior, String method, DB2CursorType reqCursorType, Boolean abortOnOptValueChg, Boolean skipDeleted, Boolean isResultSet, Int32 maxRows, Boolean skipInitialValidation)
at IBM.Data.DB2.DB2Command.ExecuteReaderObject(CommandBehavior behavior, String method)
at IBM.Data.DB2.DB2Command.ExecuteReader(CommandBehavior behavior)
at IBM.Data.DB2.DB2Command.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
at ShowConsignmentsOpen.Page_Load(Object sender, EventArgs e) in c:\Inetpub\TestStoredProc\ShowConsignmentsOpen.aspx.cs:line 50
at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest()
at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context)
at System.Web.UI.Page.ProcessRequest(HttpContext context)
at ASP.showconsignmentsopen_aspx.ProcessRequest(HttpContext context) in c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\teststoredproc\f35f719b\99c08192\App_Web_yti93vc5.2.cs:line 0
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
at System.Web.HttpApplication.ApplicationStepManager.ResumeSteps(Exception error)
at System.Web.HttpApplication.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData)
at System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr)
at System.Web.HttpRuntime.ProcessRequestNoDemand(HttpWorkerRequest wr)
at System.Web.HttpRuntime.ProcessRequest(HttpWorkerRequest wr)
at Microsoft.VisualStudio.WebHost.Request.Process()
at Microsoft.VisualStudio.WebHost.Host.ProcessRequest(Connection conn) InnerException Message: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. Check InnerException property for more detail. SQLSTATE=58005
I have a C# application, from where I am trying to call an ISeries Stored Procedure (wrapping an RPGLE program). This RPGLE program returns a result set back to my C# application.
When I try to call the stored procedure, it errors and hangs indefinitely. In the debug mode, I can see the SQL error message as shown at the end of the post. If I use OleDBConnection it works fine, but it doesn't work with DB2 Connect.
I have tried to setup Tracing on my page, but it didn't help as the page just hangs and I am not able to view the stack trace.
On ISeries side, I can see that the program executes correctly (For testing, I am writing a record in a test file at the end of the program.)
Has anybody else faced this error before? I would appreciate any help on this.
Thanks.
Code:-
DB2Connection conn1 = new DB2Connection(ConfigurationManager.ConnectionStrings ["db2IBM"].ConnectionString);
conn1.Open();
string callString5 = "PGMLIBLE.GETCONSIGNMENTS";
DB2Command cmd1 = new DB2Command(callString5, conn1);
cmd1.CommandType = CommandType.StoredProcedure;
cmd1.CommandTimeout = 5;
DB2Parameter prmCons = cmd1.Parameters.Add("prmCons", DB2Type.Char, 7);
prmCons.Direction = ParameterDirection.Input;
prmCons.Value = "JUT0016";
DB2Parameter prmCmp = cmd1.Parameters.Add("prmCmp", DB2Type.Char, 3);
prmCmp.Direction = ParameterDirection.Input;
prmCmp.Value = "DTA";
DB2Parameter prmIorE = cmd1.Parameters.Add("prmIorE", DB2Type.Char, 1);
prmIorE.Direction = ParameterDirection.Input;
prmIorE.Value = "Y";
DB2DataAdapter adp = new DB2DataAdapter(cmd1);
DataTable dt = new DataTable();
adp.Fill(dt);
// If I just execute cmd1.executeNonquery it doesn't error.
// cmd1.ExecuteNonQuery();
GridView2.DataSource = dt;
GridView2.DataBind();
conn1.Close();
conn1.Dispose();
cmd1.Dispose();
Error Message:-
ERROR [58005] [IBM][DB2.NET] SQL0902 An unexpected exception has occurred in Process: 5652 Thread 10 AppDomain: Name:aa196883-1-129406018469512609
There are no context policies.
Function: SQLExecDirectADONET (Params)
CallStack: at System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)
at System.Environment.get_StackTrace()
at IBM.Data.DB2.DB2ConnPool.HandleUnknownErrors(String strFncMsg, Exception exception, Boolean bThrow)
at IBM.Data.DB2.DB2Command.ExecuteReaderObject(CommandBehavior behavior, String method, DB2CursorType reqCursorType, Boolean abortOnOptValueChg, Boolean skipDeleted, Boolean isResultSet, Int32 maxRows, Boolean skipInitialValidation)
at IBM.Data.DB2.DB2Command.ExecuteReaderObject(CommandBehavior behavior, String method)
at IBM.Data.DB2.DB2Command.ExecuteReader(CommandBehavior behavior)
at IBM.Data.DB2.DB2Command.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
at ShowConsignmentsOpen.Page_Load(Object sender, EventArgs e) in c:\Inetpub\TestStoredProc\ShowConsignmentsOpen.aspx.cs:line 50
at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest()
at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context)
at System.Web.UI.Page.ProcessRequest(HttpContext context)
at ASP.showconsignmentsopen_aspx.ProcessRequest(HttpContext context) in c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\teststoredproc\f35f719b\99c08192\App_Web_yti93vc5.2.cs:line 0
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
at System.Web.HttpApplication.ApplicationStepManager.ResumeSteps(Exception error)
at System.Web.HttpApplication.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData)
at System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr)
at System.Web.HttpRuntime.ProcessRequestNoDemand(HttpWorkerRequest wr)
at System.Web.HttpRuntime.ProcessRequest(HttpWorkerRequest wr)
at Microsoft.VisualStudio.WebHost.Request.Process()
at Microsoft.VisualStudio.WebHost.Host.ProcessRequest(Connection conn) InnerException Message: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. Check InnerException property for more detail. SQLSTATE=58005
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我总是这样做:
我不记得如何做这个方向,但这基本上是我过去实现这一点的方式。
I have always done the following:
I can't remember how to do the direction, but this is basically how I have implemented this in the past.
这个问题很久以前就被问到了,不过我还是会回答一下。
看看这个错误消息:
在搜索“没有上下文策略。”文本后,我发现了以下内容:
MSDN AppDomain.ToString 方法
在那里,您将看到以下内容:
那么,这意味着什么呢?
最有可能的是,它来自于:
这正是你写的。
该错误可能是由以下任一原因引起的:
db2IBM
。有关设置“连接字符串”部分的帮助,请参阅以下内容:
在 ASP.NET 中设置到 SQL SERVER 的连接字符串
This was asked long ago, but I'll answer it anyway.
Take a look at this error message:
After doing a search on the text "There are no context policies.", I found this:
MSDN AppDomain.ToString Method
There, you will see the following:
So, what does this mean?
Most likely, it comes from this:
That is exactly how you wrote it.
That error could be caused by either of these:
db2IBM
does not exist in your Web.config file's Connection String section.For help with setting up your Connection String section, see the following:
Setting up connection string in ASP.NET to SQL SERVER