简体   繁体   English

如何从Visual Studio中的包管理器控制台调用针对SQL Azure的update-database?

[英]How to call update-database from package manager console in Visual Studio against SQL Azure?

I am using EF 6.1.3. 我使用的是EF 6.1.3。 I am trying to call update-database from package manager console against SQL Azure. 我试图从包管理器控制台调用update-database对SQL Azure。 Everything works fine with local SQL Express 2012. I can successfully connect to the server with SQL Server Management Studio 2012/2014 and with Visual Studio Server Explorer with the same credentials. 使用本地SQL Express 2012,一切正常。我可以使用SQL Server Management Studio 2012/2014和具有相同凭据的Visual Studio Server Explorer成功连接到服务器。 I have made an exception on the SQL Azure firewall from the management portal already but I receive the error : 我已从管理门户网站上对SQL Azure防火墙进行了例外但我收到错误:

Error Number:18456,State:1,Class:14 Login failed for user 'xxxxxxx'. 错误号码:18456,状态:1,类:14用户'xxxxxxx'登录失败。 This session has been assigned a tracing ID of 'xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'. 已为此会话分配了跟踪ID“xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx”。 Provide this tracing ID to customer support when you need assistance. 在需要帮助时,请将此跟踪ID提供给客户支持。

The exception is : 例外是:

System.Data.SqlClient.SqlException (0x80131904): Login failed for user 'xxxxx'. System.Data.SqlClient.SqlException(0x80131904):用户'xxxxx'登录失败。 This session has been assigned a tracing ID of 'xxxxxx'. 已为此会话分配了跟踪ID“xxxxxx”。 Provide this tracing ID to customer support when you need assistance. 在需要帮助时,请将此跟踪ID提供给客户支持。 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.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource 在System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject,UInt32 waitForMultipleObjectsTimeout,Boolean allowCreate,Boolean onlyOneCheckConnection,DbConnectionOptions userOptions,DbConnectionInternal&connection)处于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)的System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection,DbConnectionFactory connectionFactory,TaskCompletionSource 1 retry, DbConnectionOptions userOptions) at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource )中的DbConnectionInternal&connection) 1 retry, DbConnectionOptions userOptions) at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource 1 retry, DbConnectionOptions userOptions) at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource 1 retry, DbConnectionOptions userOptions) at System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource 1 retry) at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource 1 retry) at System.Data.SqlClient.SqlConnection.Open() at System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.b__36(DbConnection t, DbConnectionInterceptionContext c) at System.Data.Entity.Infrastructure.Interception.InternalDispatcher 1.Dispatch[TTarget,TInterceptionContext](TTarget target, Action 2 operation, TInterceptionContext interceptionContext, Action 3 executing, Action 3 executed) at System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.Open(DbConnection connection, DbInterceptionContext interceptionContext) at System.Data.Entity.SqlServer.SqlProviderServices.<>c__DisplayClass33.b__32() at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.<>c__DisplayClass1.b__0() at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy. 1 retry, DbConnectionOptions userOptions) at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource 1重试,DbConnectionOptions userOptions)System.Data.SqlClction.SqlConnection.TryOpenInner(TaskCompletionSource 1 retry) at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource 1 retry)处于System.Data.SqlClient.SqlConnection.Open( )System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.b__36(DbConnection t,DbConnectionInterceptionContext c)at System.Data.Entity.Infrastructure.Interception.InternalDispatcher 1.Dispatch[TTarget,TInterceptionContext](TTarget target, Action 2 operation, TInterceptionContext interceptionContext,Action 3 executing, Action 3执行)在System.Data.Entity.SqlServer.SqlProviderServices的System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.Open(DbConnection connection,DbInterceptionContext interceptionContext)。<> c__DisplayClass33.b__32()在System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy。<> c__DisplayClass1.b__0()处于System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy。 Execute[TResult](Func 1 operation) at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Action operation) at System.Data.Entity.SqlServer.SqlProviderServices.UsingConnection(DbConnection sqlConnection, Action 1 act) at System.Data.Entity.SqlServer.SqlProviderServices.UsingMasterConnection(DbConnection sqlConnection, Action 1 act) at System.Data.Entity.SqlServer.SqlProviderServices.CreateDatabaseFromScript(Nullable 1 commandTimeout, DbConnection sqlConnection, String createDatabaseScript) at System.Data.Entity.SqlServer.SqlProviderServices.DbCreateDatabase(DbConnection connection, Nullable 1 commandTimeout, StoreItemCollection storeItemCollection) at System.Data.Entity.Core.Common.DbProviderServices.CreateDatabase(DbConnection connection, Nullable 1 commandTimeout, StoreItemCollection storeItemCollection) at System.Data.Entity.Core.Objects.ObjectContext.CreateDatabase() at System.Data.Entity.Migrations.Utilities.DatabaseCreator.Create(DbConnection connection) at System.Da 1 operation) at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Action operation) at System.Data.Entity.SqlServer.SqlProviderServices.UsingConnection(DbConnection sqlConnection, Action 1 act)的1 operation) at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Action operation) at System.Data.Entity.SqlServer.SqlProviderServices.UsingConnection(DbConnection sqlConnection, Action执行[TResult](Func 1 operation) at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Action operation) at System.Data.Entity.SqlServer.SqlProviderServices.UsingConnection(DbConnection sqlConnection, Action1 act) at System.Data.Entity.SqlServer.SqlProviderServices.CreateDatabaseFromScript(Nullable 1 commandTimeout,DbConnection sqlConnection,String createDatabaseScript)中的Entity.SqlServer.SqlProviderServices.UsingMasterConnection(DbConnection sqlConnection,Action 1 act) at System.Data.Entity.SqlServer.SqlProviderServices.CreateDatabaseFromScript(Nullable (DbConnection连接,Nullable 1 commandTimeout, StoreItemCollection storeItemCollection) at System.Data.Entity.Core.Common.DbProviderServices.CreateDatabase(DbConnection connection, Nullable 1 commandTimeout,StoreItemCollection storeItemCollection)中()System.Da上的System.Data.Entity.Migrations.Utilities.DatabaseCreator.Create(DbConnection连接) ta.Entity.Migrations.DbMigrator.EnsureDatabaseExists(Action mustSucceedToKeepDatabase) at System.Data.Entity.Migrations.Infrastructure.MigratorBase.EnsureDatabaseExists(Action mustSucceedToKeepDatabase) at System.Data.Entity.Migrations.DbMigrator.Update(String targetMigration) at System.Data.Entity.Migrations.Infrastructure.MigratorBase.Update(String targetMigration) at System.Data.Entity.Migrations.Design.ToolingFacade.UpdateRunner.Run() at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate) at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate) at System.Data.Entity.Migrations.Design.ToolingFacade.Run(BaseRunner runner) at System.Data.Entity.Migrations.Design.ToolingFacade.Update(String targetMigration, Boolean force) at System.Data.Entity.Migrations.UpdateDatabaseCommand.<>c__DisplayClass2.<.ctor>b__0() at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command) ClientConnectionId:xxxxx 位于System的System.Data.Entity.Migrations.DbMigrator.Update(String targetMigration)的System.Data.Entity.Migrations.Infrastructure.MigratorBase.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)中的ta.Entity.Migrations.DbMigrator.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)。位于System.AppDomain.DoCallBack的System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)的System.Data.Entity.Migrations.Design.ToolingFacade.UpdateRunner.Run()中的Data.Entity.Migrations.Infrastructure.MigratorBase.Update(String targetMigration)( System.Data.Entity.Migrations.Design.ToolingFacade.Update(String targetMigration,Boolean force)中的System.Data.Entity.Migrations.Design.ToolingFacade.Run(BaseRunner runner)处于System.Data.Entity.Migrations的CrossAppDomainDelegate callBackDelegate) System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action命令)ClientConnectionId:xxxxx中的.UpdateDatabaseCommand。<> c__DisplayClass2。<。ctor> b__0()

The connection string I use is : 我使用的连接字符串是:

Update-Database -SourceMigration xxxxxx -TargetMigration xxxxx -StartUpProjectName xxxxx -ProjectName xxxxx.Migrations -ConfigurationTypeName "xxxxx.MigrationConfiguration" -ConnectionString "Server=tcp:xxxxxx.database.windows.net,1433;Database=xxxxxx;User ID=xxxxxx;Password=xxxxxx;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;" Update-Database -SourceMigration xxxxxx -TargetMigration xxxxx -StartUpProjectName xxxxx -ProjectName xxxxx.Migrations -ConfigurationTypeName“xxxxx.MigrationConfiguration”-ConnectionString“Server = tcp:xxxxxx.database.windows.net,1433; Database = xxxxxx; User ID = xxxxxx; Password = xxxxxx; Trusted_Connection = False; Encrypt = True;连接超时= 30;“ -ConnectionProviderName "System.Data.SqlClient" -Force -ConnectionProviderName“System.Data.SqlClient” - Force

I got the connection string from the portal. 我从门户网站获得了连接字符串。 Does anybody know where is the gotcha or how to troubleshoot this? 有谁知道问题在哪里或如何解决这个问题?

I find only one strange thing in the error message : Login failed for user 'xxxxxxx'. 我在错误消息中只发现一个奇怪的事情:用户'xxxxxxx'登录失败。 The user is actually xxxx@serverName. 用户实际上是xxxx @ serverName。 Is there any escape trick going on here? 这里有逃脱伎俩吗?

As I suspected - the @ character in the username breaks it. 我怀疑 - 用户名中的@字符会破坏它。 For a reason unknown to me the generated username for Sql Azure is username@serverName. 由于我不知道的原因,生成的Sql Azure用户名是username @ serverName。 When you get the connection string parameter from the Azure Management Portal and put it for EF migrations in double quotes : 从Azure管理门户获取连接字符串参数并将其用于双引号的EF迁移时:

-ConnectionString "connString with username@serverName" -ConnectionString“connString with username @ serverName”

you get the "username@serverName" cut-off so the underlying connection provider uses only "username" and not "username@serverName". 您获得“username @ serverName”截止,因此底层连接提供程序仅使用“username”而不是“username @ serverName”。

Entity Framework reads the username as "username" and not as "username@serverName" and you get rejected by the server. 实体框架将用户名读取为“用户名”而不是“username @ serverName”,您将被服务器拒绝。 Nearly every program out there has the smarts to check if you have placed or not the @serverName suffix and does the trick behind the scenes. 几乎每个程序都有智能来检查你是否放置了@serverName后缀,并在幕后做了诀窍。 EF is a bit stricter and does not. EF有点严格,但没有。 ( and I like it) ( 我喜欢它)

The solution to the problem is simple - turn around the quotes. 问题的解决方案很简单 - 转过报价。 Surround the connection string parameter with single quotes and the username with double quotes like that : 用单引号括起连接字符串参数,用双引号括起来:

-ConnectionString 'connString with "username@serverName" .... ' -ConnectionString'connString with“username @ serverName”....'

This way the username is preserver as a whole and not cut-off at the @ character and EF connects properly. 这样,用户名作为整体保留,而不是@字符的截止,EF正确连接。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Visual Studio中的程序包管理器控制台上执行“更新数据库”时,出现错误:找不到内容根文件夹 - When doing an “update-database” on the package manager console in visual studio i get error : Could not find content root folder 使用包管理器控制台“ Update-Database”等在实体框架中以编程方式连接字符串 - Programmatically connection string in entity framework with package manager console “Update-Database” etc 从visual studio命令提示符运行nuget包管理器控制台 - Run nuget package manager console from visual studio command prompt 如何从 Visual Studio 2019 更新 Azure 数据库? - How to update an Azure Database from Visual Studio 2019? 在代码优先环境中从包管理器控制台更新数据库 - update the database from package manager console in code first environment EF代码优先-从Azure门户运行更新数据库 - EF Code First - run Update-Database from Azure portal 在扩展中以编程方式访问visual studio的powershell控制台(包管理器控制台) - Access the powershell console (package manager console) of visual studio programmatically in an extension Package Manager Console Visual Studio 2019 返回新行 - Package Manager Console Visual Studio 2019 Returns New Line 在 Visual Studio 中使用 DTE 的包管理器控制台自动化 - Package Manager Console Automation using DTE in Visual Studio 从Visual Studio Online缩减Azure中托管的SQL数据库的规模 - Downscale an sql database hosted in Azure from Visual studio online
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM