简体   繁体   English

错误SQL30061N使用IBM.EntityFrameworkCore从Visual Studio 2017 c#中的DB2 iSeries提取数据

[英]Error SQL30061N pulling data from DB2 iSeries in Visual Studio 2017 c# using IBM.EntityFrameworkCore

I'm looking to pull data from a DB2 File/Table that resides on a IBM iSeries using IBM.EntityFrameworkCore This has been a difficult task and it seems like I have ran into problems all along the way. 我希望使用IBM.EntityFrameworkCore从驻留在IBM iSeries上的DB2文件/表中提取数据,这是一项艰巨的任务,似乎我一直都遇到问题。 Most of them I have been able to work through by reading comments on this site, however, I cannot find anything to help me with this one. 通过阅读本网站上的评论,大多数人都可以解决我的问题,但是,我找不到任何可以帮助我的东西。

I have performed the following steps: 我已经执行了以下步骤:

  1. Created a new Console App Project for .Net Core 为.Net Core创建了一个新的控制台应用程序项目
  2. Installed IBM.EntityFrameworkCore version 1.1.1.101 已安装IBM.EntityFrameworkCore版本1.1.1.101
  3. Updated my PATH environment variable so that it points to C:\\Users\\MyUserName.nuget\\packages\\ibm.data.db2.core\\1.1.1.101\\build\\clidriver\\bin 更新了我的PATH环境变量,使其指向C:\\ Users \\ MyUserName.nuget \\ packages \\ ibm.data.db2.core \\ 1.1.1.101 \\ build \\ clidriver \\ bin
  4. Checked to make sure the correct driver was installed and being loaded by using the db2level command from the command prompt. 通过从命令提示符下使用db2level命令检查以确保安装和加载了正确的驱动程序。
  5. Within the Console App Project I have created three classes named iSeriesContext.cs, SYSVARIABLES.cs, and Program.cs. 在控制台应用程序项目中,我创建了三个名为iSeriesContext.cs,SYSVARIABLES.cs和Program.cs的类。

For testing purposes I'm using a system Schema/Database that I believe ships standard with DB2 on the iSeries. 出于测试目的,我使用了iSchema上标准随附的系统模式/数据库。

The Program.cs contains: Program.cs包含:

using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            iSeriesContext context = new iSeriesContext();
            var results = context.SYSVARIABLES.Where(p => p.VARIABLE_NAME == "test").FirstOrDefault();
        }
    //enter code here
    }
}

The iSeriesContext.cs contains: iSeriesContext.cs包含:

using System;
using Microsoft.EntityFrameworkCore;
using System.Linq;
using IBM.EntityFrameworkCore;
using IBM.EntityFrameworkCore.Storage.Internal;

namespace ConsoleApp1
{
    public class iSeriesContext : DbContext
    {
        public iSeriesContext() : base() { }
        public DbSet<SYSVARIABLE> SYSVARIABLES { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            optionsBuilder.UseDb2(@"server=192.0.0.1:446; Database=QSYS2; userid=username; password=password", p => p.SetServerInfo(IBMDBServerType.AS400, IBMDBServerVersion.AS400_07_01));
        }
    }
}

The SYSVARIABLE.cs contains: SYSVARIABLE.cs包含:

using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    public class SYSVARIABLE
    {
        [Key]
        public string VARIABLE_SCHEMA { get; set; }
        public string VARIABLE_NAME { get; set; }
        public string SYSTEM_VAR_SCHEMA { get; set; }
    }
}

Additional Notes: 补充笔记:

I have conformed that my iSeries OS is V7R1. 我已经确认我的iSeries操作系统是V7R1。

I have confirmed that my drda service on the iSeries is listening on port 446 and when I run my code I do see the "last activity date/time" update to the current time. 我已经确认我的iSeries上的drda服务正在侦听端口446,并且在运行代码时,我确实看到“上次活动日期/时间”已更新为当前时间。

The solution compiles with no errors. 该解决方案编译没有错误。 However, when I run it I get a 但是,当我运行它时,我得到一个

"IBM.Data.DB2.Core.DB2Exception: 'External component has thrown an exception.'" error on this line "var results = context.SYSVARIABLES.Where(p => p.VARIABLE_NAME == "test").FirstOrDefault();" in Program.cs

The details of the error are: 错误的详细信息是:

IBM.Data.DB2.Core.DB2Exception occurred
  HResult=0x80004005
  Message=ERROR [08004] [IBM] SQL30061N  The database alias or database name 

"QSYS2             " was not found at the remote node.  SQLSTATE=08004
    [IBM] SQL30061N  The database alias or database name "QSYS2             " was not found at the remote node.  SQLSTATE=08004

  Source=<Cannot evaluate the exception source>
  StackTrace:
   at IBM.Data.DB2.Core.DB2ConnPool.Open(DB2Connection connection, String& szConnectionString, DB2ConnSettings& ppSettings, Object& ppConn)
   at IBM.Data.DB2.Core.DB2Connection.Open()
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.Open()
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable.Enumerator.BufferlessMoveNext(Boolean buffer)
   at Microsoft.EntityFrameworkCore.Query.QueryMethodProvider.<_ShapedQuery>d__3`1.MoveNext()
   at System.Linq.Enumerable.TryGetFirst[TSource](IEnumerable`1 source, Boolean& found)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass20_0`1.<CompileQueryCore>b__0(QueryContext qc)
   at System.Linq.Queryable.FirstOrDefault[TSource](IQueryable`1 source)
   at ConsoleApp1.Program.Main(String[] args) in C:\Users\username\source\repos\IBMEntityFrameworkTest\ConsoleApp1\Program.cs:line 10
"

I feel like I'm very close. 我觉得我很亲近。 Any help would be appreciated. 任何帮助,将不胜感激。

Can you try using ODBC to make a connection to this data source? 您可以尝试使用ODBC与该数据源建立连接吗? When you do that, you get a dialog which lets you choose the Package Library and the Library List. 完成此操作后,将出现一个对话框,您可以在其中选择“包库”和“库列表”。 The message indicates that QSYS2 is not found. 该消息表明未找到QSYS2。 So that may not be the right name for the Package. 因此,这可能不是Package的正确名称。 In the screenshot below the package name is "QGPL". 在下面的屏幕快照中,程序包名称为“ QGPL”。

Once you've got the ODBC datasource configured, test it using a very simple C# app that uses System.Data.Odbc.OdbcConnection with our connection string which simply uses that DSN. 一旦配置了ODBC数据源,就使用一个非常简单的C#应用​​程序对其进行测试,该应用程序使用System.Data.Odbc.OdbcConnection以及仅使用该DSN的连接字符串。 That way you get around any EF nonsense and can verify whether you can actually read the data you're looking for. 这样一来,您就可以解决所有EF废话,并可以验证您是否可以实际读取所需的数据。 Once you've proven you can use the DSN and connection string to read your table, then you can see if that leads to new parameters to use with EF. 一旦证明可以使用DSN和连接字符串读取表,即可查看是否导致使用EF的新参数。

Note that you could also just use plain old ODBC to read your data. 请注意,您也可以只使用普通的旧式ODBC读取数据。 This is what we do. 这就是我们要做的。 Then, once the DSN is set up we don't have to worry about DB2 nonsense beyond its wacky syntax. 然后,一旦设置了DSN,我们就不必担心其古怪的语法之外的DB2废话了。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 IBM.Data.DB2.iSeries的iSeries的.NET / C#DB2&#39;FatalExecutionEngineError&#39; - .NET/C# DB2 for iSeries 'FatalExecutionEngineError' from IBM.Data.DB2.iSeries 使用C#从NHibernate连接到AS400(iSeries)时出现错误RROR [08] [IBM] SQL30081N - Error RROR [08001] [IBM] SQL30081N when connecting to AS400 (iSeries) from NHibernate using C# 使用 IBM.EntityFrameworkCore 设置库列表 - Setting library list using IBM.EntityFrameworkCore 从C#/ ODBC枚举iSeries DB2中的表 - Enumerate tables in iSeries DB2 from C#/ODBC Visual Studio 2017:连接到 IBM.Data.DB2 失败 - Visual Studio 2017: Connection to IBM.Data.DB2 fails 如何在Visual Studio 2017中使用C#建立SQL连接? - how to build a SQL connection using C# in Visual Studio 2017? 在 IBM.EntityFrameworkCore 中指定协议 olsoctcp - specify protocol olsoctcp in IBM.EntityFrameworkCore C#ADO.Net与db2 iseries-连接无效 - C# ADO.Net to db2 iseries - connection not valid C#:如何从数据库的最后一行获取数据? 我在Visual Studio 2017中使用 - C#: How to get data from the last row in database? I'm using in visual studio 2017 如何使用C#ADO.NET中的参数将行向上插入DB2 iSeries? - How to upsert row into DB2 iSeries using parameters in C# ADO.NET?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM