我需要將我的ASP Net 5應用程序與IBM Db2數據庫連接起來。

我找到了這些nuget包:

https://www.nuget.org/profiles/IBMDB2EF

我按照本教程:

https://www.ibm.com/developerworks/community/blogs/96960515-2ea1-4391-8170-b0515d08e4da/entry/sample_ef7_application_for_ibm_data_servers?lang=en

但這不起作用。

我的project.json

"dependencies": {
"EntityFramework.IBMDataServer": "7.0.0-beta1",
. . .

}

我的Starup.cs

public void ConfigureServices(IServiceCollection services){。 。 。

        services.AddEntityFramework()
            .AddDb2()
            .AddDbContext<DB2.Models.Users.UserContext>();

        services.AddScoped<IUserRepository, UserRepository>();
    }

我的DBContext

using Microsoft.Data.Entity;
using IBM.Data.Entity;

namespace DB2.Models.Users
{
    public class UserContext: DbContext
    {
        public DbSet<User> User { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            optionsBuilder.UseDb2(@"Server=x.x.x.x;Database=x;password=x;uid=x;");
            base.OnConfiguring(optionsBuilder);
        }        
    }
}  

我的存儲庫

using System.Linq;

namespace DB2.Models.Users
{
    public class UserRepository: IUserRepository
    {
        private UserContext _context;

        public UserRepository(UserContext context)
        {
            _context = context;
        }

        public void pass()
        {
            var x = _context.User.First();            
        }
    }
}

執行此行時“var x = _context.User.First();”告訴我這個錯誤:

System.BadImageFormatException was unhandled by user code
    FileName=IBM.Data.DB2, Version=9.7.4.4, Culture=neutral, PublicKeyToken=7c307b91aa13d208
    FusionLog==== Pre-bind state information ===
LOG: DisplayName = IBM.Data.DB2, Version=9.7.4.4, Culture=neutral, PublicKeyToken=7c307b91aa13d208
    Fully-specified)
LOG: Appbase = file:///C:/Users/JOlivas/.dnx/runtimes/dnx-clr-win-x86.1.0.0-rc1-update1/bin/
LOG: Initial PrivatePath = NULL
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: No application configuration file found.
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: IBM.Data.DB2, Version=9.7.4.4, Culture=neutral, PublicKeyToken=7c307b91aa13d208
LOG: Fusion is hosted. Check host about this assembly.
LOG: Try host assembly store with assembly ibm.data.db2, version=9.7.4.4, culture=neutral, publickeytoken=7c307b91aa13d208, processorarchitecture=x86.
LOG: Try host assembly store with assembly ibm.data.db2, version=9.7.4.4, culture=neutral, publickeytoken=7c307b91aa13d208, processorarchitecture=msil.
LOG: Try host assembly store with assembly ibm.data.db2, version=9.7.4.4, culture=neutral, publickeytoken=7c307b91aa13d208.
WRN: Host assembly store does not contain this assembly.
LOG: Attempting download of new URL file:///C:/Users/JOlivas/.dnx/runtimes/dnx-clr-win-x86.1.0.0-rc1-update1/bin/IBM.Data.DB2.DLL.
ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.

    HResult=-2147024885
    Message=Could not load file or assembly 'IBM.Data.DB2, Version=9.7.4.4, Culture=neutral, PublicKeyToken=7c307b91aa13d208' or one of its dependencies. An attempt was made to load a program with an incorrect format.
    Source=EntityFramework.IBMDataServer
    StackTrace:
        at IBM.Data.Entity.Storage.Internal.Db2SqlConnection.CreateDbConnection()
        at Microsoft.Data.Entity.Internal.LazyRef`1.get_Value()
        at Microsoft.Data.Entity.Storage.RelationalConnection.Open()
        at Microsoft.Data.Entity.Query.Internal.QueryingEnumerable.Enumerator.MoveNext()
        at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
        at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)
        at lambda_method(Closure , QueryContext )
        at Microsoft.Data.Entity.Query.Internal.QueryCompiler.<>c__DisplayClass18_1`1.<CompileQuery>b__1(QueryContext qc)
        at Microsoft.Data.Entity.Query.Internal.QueryCompiler.Execute[TResult](Expression query)
        at Microsoft.Data.Entity.Query.Internal.EntityQueryProvider.Execute[TResult](Expression expression)
        at System.Linq.Queryable.First[TSource](IQueryable`1 source)
        at DB2.Models.Users.UserRepository.pass() in D:\Proyectos\MVC\NSEL\DB2\src\DB2\Models\Users\UserRepository.cs:line 16
        at DB2.Controllers.HomeController.test() in D:\Proyectos\MVC\NSEL\DB2\src\DB2\Controllers\HomeController.cs:line 33
InnerException: 

熱門答案

我看到你標記為db2400 - 這是IBM i還是iSeries?如果是這樣,它有自己的DB2版本。如果以上情況屬實,請使用IBM i Access for Windows附帶的內容並添加對以下內容的引用:

C:\ Program Files(x86)\ IBM \ Client Access \ IBM.Data.DB2.iSeries.dll

您的安裝可能位於不同的目錄中。這將為您提供訪問所需的內容。



Related

許可下: CC-BY-SA with attribution
不隸屬於 Stack Overflow
許可下: CC-BY-SA with attribution
不隸屬於 Stack Overflow