目前環境
1. 開發環境 :vs2019 ,.net stardard2.0 ,前端 vue 后端 .net core +webapi, win10企業版 資料庫本地
2. ORM 使用 ef ,codefirst
3. db2 資料庫組件:ibm.data.db2.core 版本(1.3.0.100)
ibm.EntityFrameworkCore(1.3.0.100)
4. db2 資料庫: 安裝的產品:DB2 Express-C - DB2COPY1, 版本:DB2/NT64 10.1.0
5. db2資料庫組態檔:appsettings.json
6. 配置字串為(可能存在問題請指正):
"ConnectionStrings": [
{
"Key": "default",
"Value": "Provider=IBMDADB2.DB2COPY1;Data Source=idms;Persist Security Info=True;User ID=idms;Password=idms"
}
],
"DBType": "DB2", //使用的資料庫
7. 配置代碼 DataContext.cs(部分,大牛1看就明白):
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
case DBTypeEnum.DB2:
optionsBuilder.UseDb2(CSName,p=>p.SetServerInfo(IBMDBServerType.LUW, IBMDBServerVersion.None));
break;
}
運行時,報一下錯誤,由于db2 相關資料比較少,很難找到原因,請大牛幫忙解決問題,請幫忙分析一下,如果幫助解決問題,在加一盒煙錢,哈哈。
info: Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationHandler[7]
Cookies was not authenticated. Failure message: Ticket expired
info: Microsoft.AspNetCore.ResponseCaching.ResponseCachingMiddleware[24]
No cached response available for this request.
fail: Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware[1]
An unhandled exception has occurred while executing the request.
System.AggregateException: One or more errors occurred. (Unable to resolve service for type 'Microsoft.EntityFrameworkCore.Storage.IDatabaseCreator'. This is often because no database provider has been configured for this DbContext. A provider can be configured by overriding the DbContext.OnConfiguring method or by using AddDbContext on the application service provider. If AddDbContext is used, then also ensure that your DbContext type accepts a DbContextOptions<TContext> object in its constructor and passes it to the base constructor for DbContext.) ---> System.InvalidOperationException: Unable to resolve service for type 'Microsoft.EntityFrameworkCore.Storage.IDatabaseCreator'. This is often because no database provider has been configured for this DbContext. A provider can be configured by overriding the DbContext.OnConfiguring method or by using AddDbContext on the application service provider. If AddDbContext is used, then also ensure that your DbContext type accepts a DbContextOptions<TContext> object in its constructor and passes it to the base constructor for DbContext.
at Microsoft.EntityFrameworkCore.Internal.InternalAccessorExtensions.GetService[TService](IInfrastructure`1 accessor)
at Microsoft.EntityFrameworkCore.Infrastructure.AccessorExtensions.GetService[TService](IInfrastructure`1 accessor)
at Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade.get_DatabaseCreator()
at Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade.EnsureCreatedAsync(CancellationToken cancellationToken)
at WalkingTec.Mvvm.Core.FrameworkContext.DataInit(Object allModules, Boolean IsSpa) 。
uj5u.com熱心網友回復:
幫頂吧,沒用過db2,想起以前讀取政府部門匯出的老掉牙的foxpro檔案,真是麻煩,sql寫法都不一樣。uj5u.com熱心網友回復:
謝謝支持,感謝感謝。uj5u.com熱心網友回復:
This is often because no database provider has been configured for this DbContext從這句話知道你沒有配置db2的提供者
uj5u.com熱心網友回復:
哥之前就是用foxpro的,一路用到vf 6.0,最后成了后娘養的孩子,疼心啊uj5u.com熱心網友回復:
提供者是這個嗎?
info: Microsoft.EntityFrameworkCore.Infrastructure[10403]
Entity Framework Core 2.2.6-servicing-10079 initialized 'DataContext' using provider 'IBM.EntityFrameworkCore' with options: SensitiveDataLoggingEnabled DetailedErrorsEnabled
uj5u.com熱心網友回復:
IBM.EntityFrameworkCor就是這個,看名字也看出來了
uj5u.com熱心網友回復:
先把 EF 扔到一邊,先用最基本的 System.Data(ADO.NET)來實作資料庫訪問。uj5u.com熱心網友回復:
許多人暗示別人的往往是自己的“猜出來”的,而不給出自己的除錯高層源代碼除錯資訊。這就好像是一個人磕破了頭,一味論證地上的臺階有問題,而不是檢查自己當時的行為。轉載請註明出處,本文鏈接:https://www.uj5u.com/net/29676.html
標籤:C#
