mvc application can't connect to database
当我从本地计算机运行我的项目时,我可以连接到数据库。当我发布它时,会收到一个错误(如下)。我相信这个问题与应用程序池有关,但我不知道它是什么。
这是一个全新的安装,包括操作系统
标识-应用程序池
连接字符串
1 | </connectionStrings> |
误差
过程信息:流程ID:5872进程名:w3wp.exe帐户名:IIS AppPoolDefaultAppPool
异常信息:异常类型:sqlException异常消息:与SQL Server建立连接时出现与网络相关或特定于实例的错误。找不到或无法访问服务器。验证实例名称是否正确,以及SQL Server是否配置为允许远程连接。(提供程序:命名管道提供程序,错误:40-无法打开到SQL Server的连接)at system.data.sqlclient.sqlInternalConnection.onerror(sqlException异常、Boolean BreakConnection、Action
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, Boolean withFailover)
at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, Boolean withFailover)
at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout)
at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance)
at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData)
at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
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
at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource
at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource
找不到网络路径
1 | Server Error in '/spadashboard' Application. |
超时已过期。从池获取连接之前经过的超时时间。这可能是因为所有池连接都在使用中,并且达到了最大池大小。
描述:执行当前Web请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其在代码中的来源的更多信息。
异常详细信息:System.InvalidOperationException:超时已过期。从池获取连接之前经过的超时时间。这可能是因为所有池连接都在使用中,并且达到了最大池大小。
源错误:
在执行当前Web请求期间生成了未处理的异常。有关异常的起源和位置的信息可以使用下面的异常堆栈跟踪来标识。
堆栈跟踪:
[无效操作异常:超时已过期。从池获取连接之前经过的超时时间。这可能是因为所有池连接都在使用中,并且达到了最大池大小。]system.data.providerBase.dbConnectionFactory.TryGetConnection(dbConnection OwningConnection,taskCompletionSourc
System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource
System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource
[实体异常:基础提供程序在打开时失败。]System.Data.EntityClient.EntityConnection.OpenStoreConnectionif(Boolean OpenCondition、DbConnectionStoreConnectionToOpen、DbConnection OriginalConnection、字符串异常代码、字符串尝试操作、Boolean&;CloseStoreConnectionOnFailure)+10948975system.data.entityClient.entityConnection.open()+136System.Data.Objects.ObjectContext.EnsureConnection()+91system.data.objects.objectcontext.executestoreQueryInternal(string commandText,string entitysetname,mergeoption mergeoption,object[]参数)+109system.data.objects.objectcontext.executeStoreQuery(string commandText,object[]参数)+87System.Data.Entity.Internal.InternalContext.ExecuteSqlQuery(字符串SQL,对象[]参数)+118System.Data.Entity.Internal.InternalContext.ExecuteSqlQueryAsienumerable(字符串SQL,对象[]参数)+85system.data.entity.internal.internalContext.executesqlquery(type elementtype,string sql,object[]参数)+260system.data.entity.internal.internalsqlnonsetquery.getEnumerator()+34system.data.entity.internal.internalsqlquery
System.Linq.Enumerable.FirstOrDefault(IEnumerable
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary
好,让我们尝试一下,将应用程序池标识从"AppPoolIdentity"更改为"LocalSystem"或"NetworkService"。看看这是否会使问题消失
要更改它,请转到"运行">>"inetmgr",然后按Enter键。
您应该看到您的IIS控制台。
在你的左手边,你可以看到应用程序池,用鼠标点击它,在你的右手边的屏幕上,你可以看到设置应用程序池默认值,点击它,它将弹出一个新的窗口,有许多属性。标识并选择LocalSystem或Network Service,如果选择了计算机上的本地服务用户帐户,请确保为已发布文件夹授予本地服务权限。