0

Ich muss meine ASP Net 5-Anwendung mit einer IBM Db2-Datenbank verbinden.Zugriff auf IBM db2-Datenbank mit ASP Net 5

fand ich diese nuget Paket:

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

Und ich folgte diesem Tutorial:

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

Aber das funktioniert nicht.

Mein project.json

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

}

Mein Starup.cs

public void ConfigureServices (IServiceCollection Dienste) { . . .

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

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

Mein 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); 
     }   
    } 
} 

Mein Repository

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();    
     } 
    } 
} 

Wenn führen Sie diese Linie "var x = _context.User.First();" Zeige mir diesen Fehler:

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: 
+0

Definieren Sie "funktioniert nicht". – mustaccio

Antwort

1

Ich sehe dich markiert db2400 - ist das ein IBM i oder iSeries? Wenn dies der Fall ist, hat es eine eigene Version von DB2. Wenn das Obige wahr ist, verwenden Sie, was mit IBM i Access für Windows geliefert wird, und fügen Sie einen Verweis auf Folgendes hinzu:

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

Ihre Installation könnte sich in einem anderen Verzeichnis befinden. Dadurch erhalten Sie, worauf Sie zugreifen müssen.

+0

iSeries. Ist ein Remote-Server. –

+1

Installieren Sie dann IBM i Access für Windows, um die von mir erwähnte .dll-Datei zu erhalten. –