恢复数据库后,EFG无法生成



我正在使用Entity Framework Core .NET 2.2和Microsoft SQLServer 2017,并且正在尝试更新由Entity Framework Code Generator生成的模型(数据库首次方法(。我最初能够创建我所有的实体和映射。我对数据库进行了更改,并使用.bkp文件进行还原,以更新我的本地SQL Server实例上的副本。

更新后,我在软件包管理器中使用以下CLI命令,efg生成-c" server = localhost sqlexpress; database = sola_dev; trusted_connection = true;">

,但我会收到以下错误。有人知道我在做什么错还是在哪里开始调查?它告诉我实例失败,但我对此有良好的联系。我已经尝试确保在SQLServer中对模式进行了更新,在备份后,我的所有更新都可见。我尝试创建一个新解决方案并从同一数据库生成,但我遇到了相同的错误。

12:48:21 I Loading options file: generation.yml
12:48:21 I Loading database model ...
12:48:21 F Host terminated unexpectedly
System.InvalidOperationException: Instance failure.
   at System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, Boolean withFailover)
   at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, Boolean withFailover)
   at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout)
   at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance)
   at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, Boolean applyTransientFaultHandling, String accessToken)
   at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
   at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions)
   at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
   at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
   at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
   at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
   at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
   at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
   at System.Data.SqlClient.SqlConnection.Open()
   at Microsoft.EntityFrameworkCore.SqlServer.Scaffolding.Internal.SqlServerDatabaseModelFactory.Create(DbConnection connection, IEnumerable`1 tables, IEnumerable`1 schemas)
   at Microsoft.EntityFrameworkCore.SqlServer.Scaffolding.Internal.SqlServerDatabaseModelFactory.Create(String connectionString, IEnumerable`1 tables, IEnumerable`1 schemas)
   at EntityFrameworkCore.Generator.CodeGenerator.GetDatabaseModel(IDatabaseModelFactory factory) in C:projectsentityframeworkcore-generatorsrcEntityFrameworkCore.Generator.CoreCodeGenerator.cs:line 248
   at EntityFrameworkCore.Generator.CodeGenerator.Generate(GeneratorOptions options) in C:projectsentityframeworkcore-generatorsrcEntityFrameworkCore.Generator.CoreCodeGenerator.cs:line 41
   at EntityFrameworkCore.Generator.GenerateCommand.OnExecute(CommandLineApplication application) in C:projectsentityframeworkcore-generatorsrcEntityFrameworkCore.GeneratorGenerateCommand.cs:line 76
--- End of stack trace from previous location where exception was thrown ---
   at McMaster.Extensions.CommandLineUtils.Conventions.ExecuteMethodConvention.Invoke(MethodInfo method, Object instance, Object[] arguments)
   at McMaster.Extensions.CommandLineUtils.Conventions.ExecuteMethodConvention.OnExecute(ConventionContext context)
   at McMaster.Extensions.CommandLineUtils.Conventions.ExecuteMethodConvention.<>c__DisplayClass0_0.<<Apply>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at McMaster.Extensions.CommandLineUtils.CommandLineApplication.<>c__DisplayClass142_0.<OnExecute>b__0()
   at EntityFrameworkCore.Generator.Program.Main(String[] args) in C:projectsentityframeworkcore-generatorsrcEntityFrameworkCore.GeneratorProgram.cs:line 50

generation.yml文件自生成以来就没有更改。

  namespace: '{Database.Name}'
  directory: .
database:
  connectionName: ConnectionStrings:Generator
  userSecretsId: //Removed for example
data:
  context:
    name: '{Database.Name}Context'
    baseClass: DbContext
    namespace: '{Project.Namespace}.Data'
    directory: '{Project.Directory}Data'
  entity:
    namespace: '{Project.Namespace}.Data.Entities'
    directory: '{Project.Directory}DataEntities'
  mapping:
    namespace: '{Project.Namespace}.Data.Mapping'
    directory: '{Project.Directory}DataMapping'
  query:
    generate: true
    indexPrefix: By
    uniquePrefix: GetBy
    namespace: '{Project.Namespace}.Data.Queries'
    directory: '{Project.Directory}DataQueries'
model:
  shared:
    namespace: '{Project.Namespace}.Domain.Models'
    directory: '{Project.Directory}DomainModels'
  read:
    generate: true
    name: '{Entity.Name}ReadModel'
  create:
    generate: true
    name: '{Entity.Name}CreateModel'
  update:
    generate: true
    name: '{Entity.Name}UpdateModel'
  mapper:
    generate: true
    name: '{Entity.Name}Profile'
    baseClass: AutoMapper.Profile
    namespace: '{Project.Namespace}.Domain.Mapping'
    directory: '{Project.Directory}DomainMapping'
  validator:
    generate: true
    name: '{Model.Name}Validator'
    baseClass: AbstractValidator<{Model.Name}>
    namespace: '{Project.Namespace}.Domain.Validation'
    directory: '{Project.Directory}DomainValidation'

我弄清楚了这个问题,如果您的实例失败,通常意味着您的连接字符串有问题。一旦修复了预期生成的代码。

相关内容

  • 没有找到相关文章

最新更新