【发布时间】:2020-03-25 15:36:09
【问题描述】:
我在 Amazon EC2 上运行 Windows Server 2019 的 t2-micro 实例。我已经安装了 SQL Server 和 IIS 用于 Web 开发。
我已经使用 zip 包部署了 asmx Web 服务。我已经使用 SSMS 手动创建了数据库。
使用以下连接字符串会导致错误
static string Source = @"Data Source=localhost\SQLEXPRESS;Initial Catalog=coredatabase;Integrated Security=SSPI;";
我收到以下错误
System.Data.SqlClient.SqlException: Cannot open database "coredatabase" requested by the login. The login failed.
Login failed for user 'IIS APPPOOL\DefaultAppPool'.
at 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)
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`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 SIT_Service.CoreService.checkifuserexistsinternal(String email, String mainauthtoken) in C:\Users\User\Desktop\Web Service\Web Service (1)\Web Service\WebApplication2\CoreService.asmx.cs:line 429
at SIT_Service.CoreService.register(String email, String password, String mainauthtoken) in C:\Users\User\Desktop\Web Service\Web Service (1)\Web Service\WebApplication2\CoreService.asmx.cs:line 498
【问题讨论】:
-
查看 SQL 日志,其中连接失败的实际错误是什么?
-
@Larnu
Login failed for user 'IIS APPPOOL\DefaultAppPool'. Reason: Failed to open the explicitly specified database 'coredatabase'. [CLIENT: <local machine>] -
LOGIN(IIS APPPOOL\DefaultAppPool) 是否为数据库coredatabase映射了USER? -
@Larnu 不。我已经按照下面的答案做到了。它解决了这个问题。谢谢。
标签: c# .net sql-server amazon-web-services amazon-ec2