我们的网站已发布,可以正常运行几天甚至几周。
然后没有任何更改,它突然开始引发数据库连接错误:
错误
System.Web.HttpUnhandledException (0x80004005): Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.Data.SqlClient.SqlException (0x80131904): Login failed for user 'DOMAIN\ServerName$'.
at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
at System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
at System.Data.SqlClient.SqlConnection.Open()
at System.Data.Linq.SqlClient.SqlConnectionManager.UseConnection(IConnectionUser user)
at System.Data.Linq.SqlClient.SqlProvider.get_IsSqlCe()
at System.Data.Linq.SqlClient.SqlProvider.InitializeProviderMode()
at System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression query)
at System.Data.Linq.DataContext.ExecuteCommand(String command, Object[] parameters)
at MyClass.Data.Linq.MYDB.MYDBDataContext.OnCreated()
在连接字符串中,我们使用的是正常运行的基本身份验证。
连接字符串
<add name="MYDBConnectionString" connectionString="server=DBServer;database=MYDB;user=myeuser;pwd=mypassword;Persist Security Info=False;Trusted_Connection=False;Integrated Security=False" providerName="System.Data.SqlClient" />
我的怀疑是,如果出现网络错误,并且该网站下一次尝试向应用程序池用户进行身份验证时,该网站无法访问数据库,并且从那时起,它将忽略连接字符串中设置的用户。
UPDATE:值得一提的是,iisreset或应用程序池回收后,网站可以再次正常运行,但是直到它继续尝试与错误的用户连接时,它才能访问数据库。
如何预防?我希望我的网站始终使用在连接字符串中设置的用户名和密码。
我尝试用不同的方式设置Persist Security Info
,Trusted_Connection
,Integrated Security
,但是我找不到正确的组合。
或者我还有其他设置或尝试阻止它退回到应用程序池用户的方法?
我将不胜感激。