MSSQL 错误“底层提供程序在打开时失败”IIS 部署
Posted
技术标签:
【中文标题】MSSQL 错误“底层提供程序在打开时失败”IIS 部署【英文标题】:MSSQL Error 'The underlying provider failed on Open' IIS deployment 【发布时间】:2021-09-24 10:18:44 【问题描述】:您好,我有一个使用实体框架运行的 API Web 服务没有问题,但是当我在同一台机器上的 iis 中部署它时,我得到了这个执行:
Exception: The underlying provider failed on Open.Inner Exception: System.Data.SqlClient.SqlException (0x80131904): Login failed for user 'GRUPOTOTAL99\\GTLTSISW13W10$'.\r\n en System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling, SqlAuthenticationProviderManager sqlAuthProviderManager)\r\n en System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)\r\n en System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions)\r\n en System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)\r\n en System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)\r\n en System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)\r\n en System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)\r\n en System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)\r\n en System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)\r\n en System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)\r\n en System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)\r\n en System.Data.SqlClient.SqlConnection.Open()\r\n en System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext](TTarget target, Action`2 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)\r\n en System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.Open(DbConnection connection, DbInterceptionContext interceptionContext)\r\n en System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.<>c__DisplayClass1.<Execute>b__0()\r\n en System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func`1 operation)\r\n en System.Data.Entity.Core.EntityClient.EntityConnection.Open()\r\nClientConnectionId:9a382a4d-6baf-47f6-8283-f9eb07d6c73d\r\nError Number:18456,State:1,Class:14","data":null,"result":0
它说登录失败,我可以更改任何选项或配置文件以使其正常工作吗?
这是我使用 Windows 身份验证的连接字符串
<connectionStrings>
<add name="AutogestionEntities" connectionString="metadata=res://*/Models.EntityDB.csdl|res://*/Models.EntityDB.ssdl|res://*/Models.EntityDB.msl;provider=System.Data.SqlClient;provider connection string="data source=192.168.0.215\devinst01;initial catalog=Autogestion;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
【问题讨论】:
您需要在 SQL Server 中为您的 API 应用程序池创建一个登录名。 数据库和IIS在同一台机器上吗?正如@Usama Aziz 所说,您需要为 SQL 中的应用程序身份创建一个登录名。您也可以尝试删除integrated security=True 并在connectionstring 中添加具有sysadmin 权限的用户和密码。 【参考方案1】:您需要在 SQL Server 中为您的 API 应用程序池创建一个登录名。
【讨论】:
以上是关于MSSQL 错误“底层提供程序在打开时失败”IIS 部署的主要内容,如果未能解决你的问题,请参考以下文章
当 WCF 服务到 TCP/IP 时,底层提供程序在开放实体框架上失败