gpt4 book ai didi

entity-framework - 使用 Azure Active Directory 应用程序对 SQL 数据库进行身份验证时, Entity Framework 代码首次迁移不起作用

转载 作者:行者123 更新时间:2023-12-03 00:35:10 24 4
gpt4 key购买 nike

我首先使用实体​​框架代码进行 Azure SQL Server 的数据库迁移。最近我尝试使用这篇文章https://learn.microsoft.com/en-us/azure/sql-database/sql-database-aad-authentication-configure来使用Azure Active Directory身份验证。我将 SQL 连接传递到使用应用程序访问 token 构建的 Entity Framework 。除了数据库迁移之外,一切都按预期进行。迁移数据库时,出现以下错误。如有任何帮助,我们将不胜感激。

系统.InvalidOperationException H结果=0x80131509 Message=此操作需要连接到“master”数据库。无法创建与“master”数据库的连接,因为原始数据库连接已打开并且凭据已从连接字符串中删除。提供未打开的连接。 源=EntityFramework.SqlServer 堆栈跟踪: 在 System.Data.Entity.SqlServer.SqlProviderServices.UsingMasterConnection(DbConnection sqlConnection,操作 1 act)
at System.Data.Entity.SqlServer.SqlProviderServices.CreateDatabaseFromScript(Nullable
1 commandTimeout,DbConnection sqlConnection,字符串 createDatabaseScript) 在System.Data.Entity.SqlServer.SqlProviderServices.DbCreateDatabase(DbConnection连接,可为空1 commandTimeout, StoreItemCollection storeItemCollection)
at System.Data.Entity.Core.Common.DbProviderServices.CreateDatabase(DbConnection connection, Nullable
1命令超时,StoreItemCollection storeItemCollection) 在 System.Data.Entity.Core.Objects.ObjectContext.CreateDatabase() 在 System.Data.Entity.Migrations.Utilities.DatabaseCreator.Create(DbConnection 连接) 在 System.Data.Entity.Migrations.DbMigrator.EnsureDatabaseExists(操作必须成功保持数据库) 在 System.Data.Entity.Migrations.DbMigrator.Update(字符串 targetMigration) 在 System.Data.Entity.MigrateDatabaseToLatestVersion 2.InitializeDatabase(TContext context)
at System.Data.Entity.Internal.InternalContext.<>c__DisplayClassf
1.b__e() 在 System.Data.Entity.Internal.InternalContext.PerformInitializationAction(操作操作) 在 System.Data.Entity.Internal.InternalContext.PerformDatabaseInitialization() 在 System.Data.Entity.Internal.LazyInternalContext.b__4(InternalContext c) 在 System.Data.Entity.Internal.RetryAction 1.PerformAction(TInput input)
at System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action
1 个 Action ) 在 System.Data.Entity.Internal.LazyInternalContext.InitializeDatabase() 在 System.Data.Entity.Internal.InternalContext.Initialize() 在 System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(类型实体类型) 在 System.Data.Entity.Internal.Linq.InternalSet 1.Initialize()
at System.Data.Entity.Internal.Linq.InternalSet
1.get_InternalContext() 在 System.Data.Entity.Internal.Linq.InternalSet 1.ActOnSet(Action action, EntityState newState, Object entity, String methodName)
at System.Data.Entity.Internal.Linq.InternalSet
1.添加(对象实体) 在 System.Data.Entity.DbSet`1.Add(TEntity 实体)

内部异常1:SqlException:用户“”登录失败。

最佳答案

我试图在 EF6 中做同样的事情,但发现当前的 EF6 库不可能做到这一点。问题是 DbMigrator 始终尝试使用连接字符串打开 SQL 连接,并且不允许注入(inject)打开的 SQL 连接。 https://learn.microsoft.com/en-us/dotnet/api/system.data.entity.migrations.dbmigrator?view=entity-framework-6.2.0

关于entity-framework - 使用 Azure Active Directory 应用程序对 SQL 数据库进行身份验证时, Entity Framework 代码首次迁移不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55944899/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com