.NET core 连接db2数据库问题,请大牛支持

bixuehua 2020-06-17 03:48:12
目前环境

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) 。
...全文
2454 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
许多人暗示别人的往往是自己的“猜出来”的,而不给出自己的调试高层源代码调试信息。这就好像是一个人磕破了头,一味论证地上的台阶有问题,而不是检查自己当时的行为。
  • 打赏
  • 举报
回复
先把 EF 扔到一边,先用最基本的 System.Data(ADO.NET)来实现数据库访问。
mingcsharp 2020-06-19
  • 打赏
  • 举报
回复
IBM.EntityFrameworkCor 就是这个,看名字也看出来了
bixuehua 2020-06-17
  • 打赏
  • 举报
回复
引用 3 楼 mingcsharp 的回复:
This is often because no database provider has been configured for this DbContext
从这句话知道你没有配置db2的提供者


提供者是这个吗?
info: Microsoft.EntityFrameworkCore.Infrastructure[10403]
Entity Framework Core 2.2.6-servicing-10079 initialized 'DataContext' using provider 'IBM.EntityFrameworkCore' with options: SensitiveDataLoggingEnabled DetailedErrorsEnabled
良朋 2020-06-17
  • 打赏
  • 举报
回复
哥之前就是用foxpro的,一路用到vf 6.0,最后成了后娘养的孩子,疼心啊
mingcsharp 2020-06-17
  • 打赏
  • 举报
回复
This is often because no database provider has been configured for this DbContext 从这句话知道你没有配置db2的提供者
bixuehua 2020-06-17
  • 打赏
  • 举报
回复
谢谢支持,感谢感谢。
ying1234 2020-06-17
  • 打赏
  • 举报
回复
帮顶吧,没用过db2,想起以前读取政府部门导出的老掉牙的foxpro文件,真是麻烦,sql写法都不一样。

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧