在Microsoft Azure Web应用程序中拒绝SQL Server的访问

问题描述:

我有一个发布到Microsoft Azure的Web应用程序。有两个数据库,都在Azure中的SQL Server上托管。一个处理身份验证的数据库工作得很好,我可以很好地登录/查看不涉及其他数据库的页面。当我尝试执行访问其他数据库的操作时,我在该帖子的底部看到了错误。在Microsoft Azure Web应用程序中拒绝SQL Server的访问

它必须是在Azure中的东西。当我在本地运行应用程序时,即使它仍在访问相同的Azure托管数据库,也能正常工作。这里是连接字符串(我已经改变了一些敏感的信息),我使用的,再次,无论是在本地工作的罚款:

<connectionStrings> 
<add name="IdentityConnection" connectionString="Server=tcp:{server}.database.windows.net,1433;Database=identity; ID={User};Password={pw};Trusted_Connection=False;Encrypt=True;Connection Timeout=30;" 
    providerName="System.Data.SqlClient" /> 
<add name="DataConnection" connectionString="Server=tcp:{server}.database.windows.net,1433;Database=Data;User ID={User};Password={pw};Trusted_Connection=False;Encrypt=True;Connection Timeout=30;" /> 

访问被拒绝

说明:未处理的异常发生在执行当前Web请求期间。请查看堆栈跟踪以获取有关该错误的更多信息以及源代码的位置。

异常详细信息:System.ComponentModel.Win32Exception:访问被拒绝

源错误:

在当前web请求的执行过程中生成未处理的异常。关于异常的来源和位置的信息可以使用下面的异常堆栈跟踪来标识。

堆栈跟踪:

[Win32Exception(0X80004005):访问被拒绝]

[SQLEXCEPTION(0x80131904):在与SQL Server建立连接时出现与网络相关的或特定于实例的错误。服务器未找到或无法访问。验证实例名称是否正确,并将SQL Server配置为允许远程连接。 (提供程序:命名管道提供程序,错误:40 - 无法打开连接到SQL Server)] System.Data.SqlClient.SqlInternalConnection.OnError(SqlException异常,布尔breakConnection,操作1 wrapCloseInAction) +5341687 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +546 System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, Boolean withFailover) +5353471 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) +923 System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance) +311 System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData) +646 System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) +278 System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) +38 System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) +732 System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) +85 System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) +1057 System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource 1重试,DbConnectionOptions userOptions,DbConnectionInternal &连接) 78 System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(的DbConnection owningConnection,TaskCompletionSource 1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) +196 System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource 1重试,DbConnectionOptions USEROPTIONS)146 System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(的DbConnection outerConnection,DbConnectionFactory connectionFactory的,TaskCompletionSource 1 retry, DbConnectionOptions userOptions) +16 System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource 1重试)94 System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)+110 System.Data.SqlClient.SqlConnect ion.Open()+96 License_Project_Web.View_Licenses.Page_Load(Object sender,EventArgs e)+43 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender,EventArgs e)+51 System.Web.UI.Control。的OnLoad(EventArgs的)92 System.Web.UI.Control.LoadRecursive()54 System.Web.UI.Page.ProcessRequestMain(布尔includeStagesBeforeAsyncPoint,布尔includeStagesAfterAsyncPoint)772

那么,事实证明,这是一个实际上发布到网络的变化的问题。从Visual Studio配置。尽管整个项目的一些总体发布以及单独发布到web.config中,但Azure中托管的web.config版本保持不变,仍然在连接字符串中引用本地数据库。通过服务器资源管理器中的网站文件直接编辑web.config,这让我能够解决这个问题,虽然有点问题。

在管理门户,有您是否为Azure服务启用了SQL Azure服务器防火墙? http://azure.microsoft.com/en-us/documentation/articles/sql-database-get-started/#ConfigFirewall

+0

是的,已经启用。 给我提供错误的数据库是在本地服务器上创建的,然后我将.BACPAC导出到Azure存储。如果原始本地服务器使用Windows身份验证,可能以某种方式反映在数据库中并导致拒绝访问? – 2014-09-03 21:07:07