首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Pomelo.EntityFrameworkCore.MySql -连接字符串

Pomelo.EntityFrameworkCore.MySql -连接字符串
EN

Stack Overflow用户
提问于 2021-08-02 00:49:09
回答 1查看 2.9K关注 0票数 0

我是dotnet和EF的新手。

目前,我正在启动一个控制台应用程序,并已收到错误。

DBContext

代码语言:javascript
运行
复制
     protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
     optionsBuilder.UseMySql(ServerVersion.AutoDetect(
        "server=localhost; port=3306; database=DB; user=root; password=test; Persist Security Info=False; Connect Timeout=300"));
        }

错误

代码语言:javascript
运行
复制
System.InvalidOperationException: A relational store has been configured without specifying either the DbConnection or connection string to use.
   at Pomelo.EntityFrameworkCore.MySql.Internal.MySqlOptions.GetConnectionSettings(MySqlOptionsExtension relationalOptions)
   at Pomelo.EntityFrameworkCore.MySql.Internal.MySqlOptions.Initialize(IDbContextOptions options)
   at Microsoft.EntityFrameworkCore.Internal.SingletonOptionsInitializer.EnsureInitialized(IServiceProvider serviceProvider, IDbContextOptions options)
   at Microsoft.EntityFrameworkCore.Internal.ServiceProviderCache.<>c__DisplayClass4_0.<GetOrAdd>g__BuildServiceProvider|3()
   at Microsoft.EntityFrameworkCore.Internal.ServiceProviderCache.<>c__DisplayClass4_0.<GetOrAdd>b__2(Int64 k)
   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
   at Microsoft.EntityFrameworkCore.Internal.ServiceProviderCache.GetOrAdd(IDbContextOptions options, Boolean providerRequired)
   at Microsoft.EntityFrameworkCore.DbContext.get_InternalServiceProvider()
   at Microsoft.EntityFrameworkCore.DbContext.Microsoft.EntityFrameworkCore.Infrastructure.IInfrastructure<System.IServiceProvider>.get_Instance()
   at Microsoft.EntityFrameworkCore.Infrastructure.Internal.InfrastructureExtensions.GetService[TService](IInfrastructure`1 accessor)
   at Microsoft.EntityFrameworkCore.Infrastructure.AccessorExtensions.GetService[TService](IInfrastructure`1 accessor)
   at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(Func`1 factory)
   at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(String contextType)
   at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.AddMigration(String name, String outputDir, String contextType, String namespace)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(String name, String outputDir, String contextType, String namespace)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigration.<>c__DisplayClass0_0.<.ctor>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
A relational store has been configured without specifying either the DbConnection or connection string to use.
EN

Stack Overflow用户

发布于 2022-05-31 08:26:59

我也有同样的错误信息。

代码语言:javascript
运行
复制
var serverVersion = new MySqlServerVersion(new Version(8, 0, 27));
    
services.AddDbContext<AppDbContext>(options => options.UseMySql("server=localhost;user=user;password=password;database=db", serverVersion));

有了这段代码,它就能工作了。有关更多信息,请参见来自Pomelo的官方文档

票数 1
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68615394

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档