我正在使用EF 6.1.3。我正在尝试针对SQL Azure从程序包管理器控制台调用update-database。本地SQL Express 2012一切正常。我可以使用SQL Server Management Studio 2012/2014和具有相同凭据的Visual Studio Server Explorer成功连接到服务器。我已经从管理门户网站对SQL Azure防火墙进行了例外处理,但是我收到错误消息:
错误号:18456,状态:1,类:14用户“ xxxxxxx”的登录失败。已为该会话分配跟踪ID“ xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx”。需要帮助时,将此跟踪ID提供给客户支持。
例外是:
System.Data.SqlClient.SqlException(0x80131904):用户'xxxxx'的登录失败。此会话已分配了跟踪ID“ xxxxxx”。需要帮助时,将此跟踪ID提供给客户支持。System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject,TaskCompletionSource)上的System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject,UInt32 waitForMultipleObjectsTimeout,Boolean allowCreate,Boolean onlyOneCheckConnection,DbConnectionOptions userOptions,DbConnectionInternal&connection)
1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource
1重试,DbConnectionOptions USEROPTIONS,DbConnectionInternal oldConnection,DbConnectionInternal&连接)在System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(的DbConnection outerConnection,DbConnectionFactory connectionFactory的,TaskCompletionSource1 retry, DbConnectionOptions userOptions) at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource
1重试,DbConnectionOptions USEROPTIONS)在System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource1 retry) at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource
1重试)在System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.b__36(DbConnection t,DbConnectionInterceptionContext c)在System.Data.Entity.Infrastructure.Interception.InternalDispatcher1.Dispatch[TTarget,TInterceptionContext](TTarget target, Action
2操作,TInterceptionContext InterceptionContext,动作3 executing, Action
在System.Data.Entity.SqlServer.SqlProviderServices。<> c__DisplayClass33.b__32()在System.Data.Entity.SqlServer的System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.Open(DbConnection连接,DbInterceptionContext拦截上下文)处执行3。 System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute [TResult](Func1 operation) at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Action operation) at System.Data.Entity.SqlServer.SqlProviderServices.UsingConnection(DbConnection sqlConnection, Action
1 act)在System.Data.Entity.SqlServer.SqlProviderServices.UsingMasterConnection(DbConnection sqlConnection,Action1 act) at System.Data.Entity.SqlServer.SqlProviderServices.CreateDatabaseFromScript(Nullable
1 commandTimeout 。<> c__DisplayClass1.b__0()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个命令超时,System.Data.Entity.Core.Objects.ObjectContext.CreateDatabase()位于System.Data.Entity.Migrations.Utilities.DatabaseCreator.Create(DbConnection连接)位于System.Data.Entity.Migrations.DbMigrator System.Data.Entity.Migrations.Infrastructure.MigratorBase.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)位于System.Data.Entity.Migrations.DbMigrator.Update(String targetMigration)位于System.Data.Entity.Migrations System.Data.Entity.Migrations.Design.ToolingFacade.UpdateRunner.Run()(位于System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)处的.MigratorBase.Update(String targetMigration)位于System.Data处的System.AppDomain.DoCallBack(CrossAppDomainDelegate处的CallBackDelegate)处的。 .Entity.Migrations.Design。System.Data.Entity.Migrations.Design.ToolingFacade.Update(String targetMigration,Boolean force)处于System.Data.Entity.Migrations.UpdateDatabaseCommand。<> c__DisplayClass2。<。ctor> b__0()在System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(操作命令)ClientConnectionId:xxxxx
我使用的连接字符串是:
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;密码= xxxxxx;受信任的连接= False;加密=正确;连接超时= 30;“ -ConnectionProviderName“ System.Data.SqlClient”-强制
我从门户网站获得了连接字符串。有人知道陷阱在哪里或如何解决这个问题?
我在错误消息中仅发现一件奇怪的事情:用户'xxxxxxx'登录失败。用户实际上是xxxx @ serverName。这里有任何逃生把戏吗?
我怀疑-用户名中的@字符将其破坏。由于我不知道的原因,Sql Azure生成的用户名是username @ serverName。当您从Azure管理门户获取连接字符串参数并将其用于EF迁移时,将其放在双引号中:
-ConnectionString“ connString with username @ serverName”
您会截取到“ username @ serverName”,因此基础连接提供程序仅使用“ username”,而不使用“ username @ serverName”。
实体框架将用户名读取为“用户名”,而不是“ username @ serverName”,您将被服务器拒绝。几乎那里的每个程序都有技巧来检查您是否放置了@serverName后缀,并在幕后进行操作。EF有点严格,但没有。( 我喜欢它)
解决问题的方法很简单-将引号转过来。连接字符串参数用单引号括起来,用户名用双引号括起来:
-ConnectionString'带有“ username @ serverName”的connString ....'
这样,用户名是一个整体保留者,不会在@字符处切断,EF会正确连接。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句