IIS Connection string to SQL Server

0

After publishing the project in IIS received an error: Error

LogFile:

2019-11-26 11:33:55.5348 | Microsoft.EntityFrameworkCore.Diagnostics.EventDefinition`2.Log | ERROR | An error occurred using the connection to database 'Appdb' on server '(LocalDb)\MSSQLLocalDB'. 

2019-11-26 11:33:55.5931 | Microsoft.EntityFrameworkCore.Diagnostics.EventDefinition`3.Log | ERROR | An exception occurred while iterating over the results of a query for context type 'App.DataAccessLayer.AppContext.ApplicationContext'.
Microsoft.Data.SqlClient.SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 50 - Local Database Runtime error occurred. Cannot create an automatic instance. See the Windows Application event log for error details.
)
 ---> System.ComponentModel.Win32Exception (0x89C50118): Unknown error (0x89c50118)
   at Microsoft.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, Boolean applyTransientFaultHandling, String accessToken, DbConnectionPool pool, SqlAuthenticationProviderManager sqlAuthProviderManager)
   at Microsoft.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
   at Microsoft.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions)
   at Microsoft.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
   at Microsoft.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
   at Microsoft.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
   at Microsoft.Data.ProviderBase.DbConnectionPool.WaitForPendingOpen()
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenDbConnectionAsync(Boolean errorsExpected, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenDbConnectionAsync(Boolean errorsExpected, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenAsync(CancellationToken cancellationToken, Boolean errorsExpected)
   at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Query.RelationalShapedQueryCompilingExpressionVisitor.AsyncQueryingEnumerable`1.AsyncEnumerator.MoveNextAsync()
ClientConnectionId:00000000-0000-0000-0000-000000000000
Error Number:-1983577832,State:0,Class:20 

2019-11-26 11:33:55.6073 | Microsoft.AspNetCore.Hosting.HostingLoggerExtensions.ApplicationError | FATAL | Application startup exception 

Connection string:

data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true

Connection string

c#
asp.net
iis
core
asked on Stack Overflow Nov 26, 2019 by Roman • edited Nov 29, 2019 by Pranav Singh

1 Answer

0

It looks like you do not have SQL Express or SQL Server installed on the IIS server (not a good idea to have the database server AND the app installed on the same machine).

Here is your problem:

The *server was not found* or was not accessible.

I recommend that you install SQL Express on a different machine, attach your database and point your connection to that database server.

answered on Stack Overflow Nov 29, 2019 by Hounddog75

User contributions licensed under CC BY-SA 3.0