Azure的网站不能访问的Azure数据库 [英] Azure website cannot access Azure DB

查看:134
本文介绍了Azure的网站不能访问的Azure数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个错误我逼疯了,我甚至不能重现!

我发表我的网站到Windows Azure和SQL Azure和它的工作太棒了。
突然之间,它不工作,我得到这个讨厌的错误:

以下是错误我得到:

http://jsfiddle.net/shimmy/pcS7g/embedded/result

下面的错误:


  

建立SQL Server的连接时发生网络相关的或特定于实例的错误。服务器未找到或无法访问。验证实例名称是否正确,以及SQL Server配置为允许远程连接。 (提供者:SQL网络接口,错误:26 - 错误定位指定的服务器/实例)


我要强调的是,我可以访问通过SSMS或VS的SQL,看看我的表等。

我不知道是什么原因导致每一个部署后频频发生这恼人的错误。

堆栈跟踪:

  [SQLEXCEPTION(0x80131904):在与SQL Server建立连接时出现与网络相关的或特定于实例的错误。服务器未找到或无法访问。验证实例名称是否正确,以及SQL Server配置为允许远程连接。 (提供者:SQL网络接口,错误:26  - 错误定位服务器/实例指定)
   System.Data.SqlClient.SqlInternalConnection.OnError(SqlException异常,布尔breakConnection,Action`1 wrapCloseInAction)5295167
   System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj,布尔callerHasConnectionLock,布尔asyncClose)+242
   System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo,SqlInternalConnectionTds connHandler,布尔ignoreSniOpenTimeout,Int64的timerExpire,布尔值加密,布尔trustServerCert,布尔integratedSecurity布尔withFailover)5307115
   System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo,字符串NEWPASSWORD,SecureString的newSecurePassword,布尔ignoreSniOpenTimeout,TimeoutTimer超时,布尔withFailover)+145
   System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo,字符串NEWPASSWORD,SecureString的newSecurePassword,布尔redirectedUserInstance,SqlConnectionString connectionOptions,SqlCredential凭证,TimeoutTimer超时)920
   System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer超时,SqlConnectionString connectionOptions,SqlCredential凭证,字符串NEWPASSWORD,SecureString的newSecurePassword,布尔redirectedUserInstance)307
   System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity身份,SqlConnectionString connectionOptions,SqlCredential凭证,对象providerInfo,字符串NEWPASSWORD,SecureString的newSecurePassword,布尔redirectedUserInstance,SqlConnectionString userConnectionOptions)434
   System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions选项,DbConnectionPoolKey poolKey,对象poolGroupProviderInfo,池类DBConnectionPool,的DbConnection owningConnection,DbConnectionOptions USEROPTIONS)5309659
   System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(的DbConnection owningConnection,DbConnectionPoolGroup poolGroup,DbConnectionOptions USEROPTIONS)+38
   System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(的DbConnection owningConnection,TaskCompletionSource`1重试,DbConnectionOptions USEROPTIONS,DbConnectionInternal&安培;连接)5311874
   System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(的DbConnection outerConnection,DbConnectionFactory connectionFactory的,TaskCompletionSource`1重试,DbConnectionOptions USEROPTIONS)+143
   System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1重试)+83
   System.Data.SqlClient.SqlConnection.Open()+96
   System.Web.Management.SqlServices.GetSqlConnection(字符串服务器,用户字符串,字符串密码,布尔信赖,字符串的connectionString)+76[HttpException(0x80004005的):无法连接到SQL Server数据库]
   System.Web.Management.SqlServices.GetSqlConnection(字符串服务器,用户字符串,字符串密码,布尔信赖,字符串的connectionString)+131
   System.Web.Management.SqlServices.SetupApplicationServices(字符串服务器,用户字符串,字符串密码,布尔信赖,字符串的connectionString,数据库字符串,字符串dbFileName,SqlFeatures功能,布尔安装)+89
   System.Web.Management.SqlServices.Install(数据库字符串,字符串dbFileName,字符串的connectionString)+27
   System.Web.DataAccess.SqlConnectionHelper.CreateMdfFile(字符串fullFileName,DATADIR字符串,字符串的connectionString)+386

更新

下面是连接字符串的副本,因为它们出现在服务器上的web.config:

 <&是connectionStrings GT;
  <添加名称=背景的connectionString =数据源= TCP:abcdefg.database.windows.net,1433;初始目录=数据库;用户ID = @摆振的tcp:ABCDEFG;密码= my123password;的providerName =System.Data.SqlClient的/>
  <添加名称=寄存的connectionString =DefaultEndpointsProtocol = https和帐户名= ACCOUNTNAME; AccountKey = accountkey ==/>
< /&是connectionStrings GT;

我甚至试图从服务器的web.config文件完全删除连接字符串。我不知道该在哪里的App_Data 的东西是从哪里来的!

我的的DbContext 是这样的:

 公共上下文()
  :基地(NAME =语境)//我也尝试过上下文独
{
}


解决方案

看来,你的应用程序期待能够用你的项目的附加文件建立一个数据库的SQL Server防爆$ P $的本地实例PSS。在错误消息中的关键行是:


  

连接字符串指定本地SQL Server防爆preSS实例
  使用应用程序的App_Data目录中的数据库位置。


您可能需要在配置文件中以匹配您的Azure网站的连接字符串更新连接字符串。可以在Azure的仪表板来获得这些信息,一旦你建立了与SQL Server的网站,并通过仪表盘一样设定。

下面是这样做很好的说明:的http:/ /blog.davidebbo.com/2012/09/managing-database-connections-in-azure.html

This error drives me crazy and I can't even reproduce it!

I've published my website to Windows Azure and SQL Azure and it worked great. All the sudden and it doesn't work, I get this nasty error:

Here is the error I get:

http://jsfiddle.net/shimmy/pcS7g/embedded/result

Here's the error:

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

I want to emphasize that I can access the SQL via SSMS or VS and see my tables etc.

I have no clue what causes this annoying error that happens again and again after every deployment.

Stack trace:

[SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)]
   System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +5295167
   System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +242
   System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, Boolean withFailover) +5307115
   System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, Boolean withFailover) +145
   System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout) +920
   System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance) +307
   System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions) +434
   System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) +5309659
   System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions) +38
   System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) +5311874
   System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +143
   System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) +83
   System.Data.SqlClient.SqlConnection.Open() +96
   System.Web.Management.SqlServices.GetSqlConnection(String server, String user, String password, Boolean trusted, String connectionString) +76

[HttpException (0x80004005): Unable to connect to SQL Server database.]
   System.Web.Management.SqlServices.GetSqlConnection(String server, String user, String password, Boolean trusted, String connectionString) +131
   System.Web.Management.SqlServices.SetupApplicationServices(String server, String user, String password, Boolean trusted, String connectionString, String database, String dbFileName, SqlFeatures features, Boolean install) +89
   System.Web.Management.SqlServices.Install(String database, String dbFileName, String connectionString) +27
   System.Web.DataAccess.SqlConnectionHelper.CreateMdfFile(String fullFileName, String dataDir, String connectionString) +386

Update

Here is a copy of the connection strings as they appear on the server's web.config:

<connectionStrings>
  <add name="Context" connectionString="Data Source=tcp:abcdefg.database.windows.net,1433;Initial Catalog=Database;User Id=shimmy@tcp:abcdefg;Password=my123password;" providerName="System.Data.SqlClient" />
  <add name="Storage" connectionString="DefaultEndpointsProtocol=https;AccountName=accountname;AccountKey=accountkey==" />
</connectionStrings>

I even tried to remove the connection strings entirely from the server's web.config. I have no clue where this App_Data thing is coming in from!

My DbContext looks like this:

public Context()
  : base("name=Context") //I also tried "Context" alone
{
}

解决方案

It appears that your application is expecting to be able to set up a database using an attached file in your project on a local instance of SQL Server Express. The key line in your error message is:

The connection string specifies a local Sql Server Express instance using a database location within the application's App_Data directory.

You probably need to update the connection string in your configuration file to match the connection string in your Azure website. This information can be obtained in the Azure dashboard once you set up the website with a SQL Server, and be set through the same dashboard.

Here's good instructions for doing that: http://blog.davidebbo.com/2012/09/managing-database-connections-in-azure.html

这篇关于Azure的网站不能访问的Azure数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆