0

I installed SQL Server recent version and save and load data from .NET project to SQL as localhost and using it.

There is no problem actually using it, but when I restart the PC, SqlConnection.Open() will get:

provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server.

If I try again after about 3 minutes, it can connect well in the same part.

I need advice on why this is happening and how to connect quickly after PC boot.

This is what can I see in error exception detail

   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.ProviderBase.DbConnectionClosed.TryOpenConnection(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()
Dale K
  • 25,246
  • 15
  • 42
  • 71
Boom_boom
  • 13
  • 2
  • How are you loading your application after reboot? – Ross Bush Mar 17 '23 at 01:42
  • If your app runs as a Windows service, add a dependency on the SQL Server service. – Dan Guzman Mar 17 '23 at 01:46
  • @RossBush Just click the .exe file to run it – Boom_boom Mar 17 '23 at 02:00
  • @DanGuzman like this? https://stackoverflow.com/questions/995403/how-can-i-define-a-dependency-on-sql-server-in-a-windows-service-that-works-with – Boom_boom Mar 17 '23 at 02:13
  • 1
    You'll probably need more than a dependency of the SQL Server service because although the Windows Service starts immediately it will take some time for SQL Server to validate all of the system database and user database files before it starts listening to accept connections. It depends on how big the files are (and the available resources) as to how quickly this happens, but tens of seconds can be typical. If SQL Server is having to compete for resources against a system booting up a desktop environment then it could take longer. – AlwaysLearning Mar 17 '23 at 02:18

0 Answers0