[英]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: 我已经执行了以下步骤:
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.