c#to AS400 / JD Edwards - 运行程序 - 未找到数据源名称且未指定默认驱动程序

时间:2013-03-04 14:57:48

标签: c# database-connection ado ibm-midrange jdedwards

更新:以下代码示例有效。我改变了连接字符串。那就是问题所在。有关替代(非ADO)解决方案,请参阅评论中的Mike Wills链接。

我有一个c#类(如果我能使它工作)运行在AS / 400上用RPG代码编写的程序 - JD Edwards。我对AS / 400和/或JD Edwards几乎一无所知。

我的(Intranet)Web应用程序中有其他类连接到JD Edwards,运行SQL查询和设置/获取数据。所有这些都使用IBM.Data.DB2.iSeries dll并且运行良好。

为此,我使用前面提到的dll编写了一个类似的类,但它没有用。我甚至在网上看到你无法使用这个dll运行程序。我发现有点可疑,但根据我的JD Edwards同事的建议,我取消了课程并使用adodb dll重新编写了它。此程序运行不需要返回任何数据。我只想让程序运行。

以下是该类的模仿版本:

    private void runJDEProgram() {
        ADODB.Connection cn = new ADODB.Connection();

        cn.ConnectionString = "Provider=ABABAB;Data Source=111.111.111";



        ADODB.Command cmdDetail = new ADODB.Command();
        cn.Open(); //has to be open before setting an active connection.
        cmdDetail.ActiveConnection=cn;


        cmdDetail.CommandType = ADODB.CommandTypeEnum.adCmdText;

        cmdDetail.CommandText = "{{CALL BLAH.BLAH(?,?)}}";


        cmdDetail.Prepared = true;

        cmdDetail.Parameters.Append(cmdDetail.CreateParameter("P1", ADODB.DataTypeEnum.adChar, ADODB.ParameterDirectionEnum.adParamInput, 10, "BLAH123"));
        cmdDetail.Parameters.Append(cmdDetail.CreateParameter("P2", ADODB.DataTypeEnum.adChar, ADODB.ParameterDirectionEnum.adParamInput, 10, "BLAH456"));

        object dummy = Type.Missing; //otherwise, we couldn't get past this.

        cmdDetail.Execute(out dummy, ref dummy, 0);

        cn.Close();
    }

这是运行时出现的错误:

{"[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified"}

我搞砸了哪里?谢谢!

编辑:连接字符串在查询AS / 400以获取/设置数据时有效。是否需要针对此类操作进行修改,还是与ADO一起使用?

1 个答案:

答案 0 :(得分:0)

由于某种原因,连接字符串必须与此不同。对于仅运行查询的其他类,我不使用相同的连接字符串。上面的连接字符串工作正常(当然有适当的值)。

它会提示输入密码,但这里的JDE人员想要这个。