Error connecting to SQL Azure Database

会有一股神秘感。 提交于 2019-12-08 05:06:30

问题


The below error occurs often. I wonder if anyone has ever experienced this or what would be the reason?

I use Entity Framework 4.0 and. NET 4.0 and Visual Studio 2010 and Windows Azure SDK 1.7 and 2.0.

Below is the connection string:

<add name="MyEntities" 
    connectionString="metadata=res://*/Model.ModelMy.csdl|res://*/Model.ModelMy.ssdl|res://*/Model.ModelMy.msl;
        provider=System.Data.SqlClient;
        provider connection string=&quot;
        data source=myserver.database.windows.net;
        initial catalog=MyDatabase;
        persist security info=True;
        user id=myUser;
        password=myPassword;
        multipleactiveresultsets=True;
        Trusted_Connection=False;
        Encrypt=True;
        Connection Timeout=30;
        App=EntityFramework&quot;" 
    providerName="System.Data.EntityClient"
 />

Error information:

Server Error in '/' Application.

Database 'MyDatabase' on server '[NAMEMYSERVER]' is not currently available. Please retry the connection later. If the problem persists, contact customer support, and provide them the session tracing ID of 'efb529ba-14eb-46d0-8311-d48b03435cee'.
Login failed for user 'myUser'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Database 'MyDatabase' on server '[NAMEMYSERVER]' is not currently available. Please retry the connection later. If the problem persists, contact customer support, and provide them the session tracing ID of 'efb529ba-14eb-46d0-8311-d48b03435cee'.
Login failed for user 'myUser'.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[SqlException (0x80131904): Database 'MyDatabase' on server '[NAMEMYSERVER]' is not currently available. Please retry the connection later. If the problem persists, contact customer support, and provide them the session tracing ID of 'efb529ba-14eb-46d0-8311-d48b03435cee'.
Login failed for user 'myUser'.]
   System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +706
   System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +89
   System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +6425518
   System.Data.SqlClient.SqlConnection.Open() +300
   System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean& closeStoreConnectionOnFailure) +67

[EntityException: The underlying provider failed on Open.]
   System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) +4728195
   System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) +1725
   MyProjectRules.Negocio.MyDatabaseHotel.HotelRN.PesquisarTodos(Include include) +0
   MyProjectWebRole.MyDatabaseHotel.Views.ListaHoteis.CarregarGridViewEntidade() +183
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +25
   System.Web.UI.Control.LoadRecursive() +71
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3064

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.551

回答1:


Step 1: Simplify your connection string. Ours looks like this:

  <add name="[CONTEXTNAME]"
     providerName="System.Data.SqlClient"
     connectionString="
      Server=tcp:[SERVER].database.windows.net,1433;
          Database=[DATABASE];
          User ID=[USER]@[SERVER];
          Password=[PASSWORD];
          Trusted_Connection=False;
          Encrypt=True;
          Connection Timeout=30;"/>

So looking at your connection string, I would try something like:

  <add name="MyEntities"
     providerName="System.Data.SqlClient"
     connectionString="
          metadata=res://*/Model.ModelMy.csdl|res://*/Model.ModelMy.ssdl|res://*/Model.ModelMy.msl;
          Server=myserver.database.windows.net;
          Database=MyDatabase;
          User id=myUser@myserver;
          Password=myPassword;
          Multipleactiveresultsets=True;
          Trusted_Connection=False;
          Encrypt=True;
          Connection Timeout=30;
          App=EntityFramework;" />

Step 2: It looks like you "User id" is missing the server name. It needs to be myUser@myServer. Try adding that back in.

Step 3: Probably not critical, but you're missing the ",1433" from the server address



来源:https://stackoverflow.com/questions/16926195/error-connecting-to-sql-azure-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!