使用IBM DB2 Connect驱动程序在i Series上调用存储过程

我有一个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:InetpubTestStoredProcShowConsignmentsOpen.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:WINDOWSMicrosoft.NETFrameworkv2.0.50727Temporary ASP.NET Filesteststoredprocf35f719b99c08192App_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
    
已邀请:
我一直做以下事情:
    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;

    cmd1.Parameters.Add("prmCons", DB2Type.Char, 7).Value = "JUT0016";
    prmCons.Direction = ParameterDirection.Input;

    cmd1.Parameters.Add("prmCmp", DB2Type.Char, 3).Value = "DTA";
    prmCmp.Direction = ParameterDirection.Input;

    cmd1.Parameters.Add("prmIorE", DB2Type.Char, 1).Value = "Y";
    prmIorE.Direction = ParameterDirection.Input;

    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();
我不记得如何做方向,但这基本上是我过去实现的方式。     
很久以前就问过了这个问题,但无论如何我都会回答。 看一下这个错误信息:   错误[58005] [IBM] [DB2.NET] SQL0902进程中发生意外异常:5652线程10 AppDomain:名称:aa196883-1-129406018469512609   没有上下文策略。 在搜索了“没有上下文策略”之后,我发现了这个: MSDN AppDomain.ToString方法 在那里,您将看到以下内容:   回报价值   键入:System.String   通过连接文字字符串“Name:”,应用程序域的友好名称以及上下文策略的字符串表示形式或字符串“没有上下文策略”而形成的字符串。 那么这是什么意思? 最有可能的是,它来自于:
ConfigurationManager.ConnectionStrings  ["db2IBM"].ConnectionString
这正是你写它的方式。 该错误可能是由以下任何一种引起的: 那些空间导致错误,或 您的Web.config文件的“连接字符串”部分中不存在
db2IBM
。 有关设置“连接字符串”部分的帮助,请参阅以下内容: 在ASP.NET中设置连接字符串到SQL SERVER     

要回复问题请先登录注册