我有一个发布到Microsoft Azure的Web应用程序。有两个数据库,都托管在Azure中的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 exception,Boolean breakConnection,Action 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 retry,DbConnectionOptions userOptions,DbConnectionInternal&amp; connection)+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 retry,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 retry)+94
System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)+110
System.Data.SqlClient.SqlConnection.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 e)+92
System.Web.UI.Control.LoadRecursive()+54
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint,Boolean includeStagesAfterAsyncPoint)+772
答案 0 :(得分:3)
嗯,事实证明,从Visual Studio发布对web.config的更改实际上是一个问题。尽管整个项目的几个整体发布和个人单独发布到web.config,但是Azure中托管的web.config的版本保持不变,仍然在连接字符串中引用了本地数据库。通过服务器资源管理器中的网站文件直接编辑web.config允许我解决问题。虽然是讽刺性的。
答案 1 :(得分:0)
在管理门户中,您是否为Azure服务启用了SQL Azure服务器防火墙? http://azure.microsoft.com/en-us/documentation/articles/sql-database-get-started/#ConfigFirewall