OleDB connection only works when debugging

I have a C # application that connects to a named instance of SQL Express on a local machine using OleDBConnection:

_connection = new OleDbConnection(_strConn);
_connection.Open();

_strConn is something like this: "Provider=sqloledb;Data Source=.\NAMEDINSTANCE;Initial Catalog=dbname;User Id=sa;Password=password;"

If I debug the application, the connection works fine. If I run the application from Windows Explorer (the same debug compilation), I get "OleDBException: Login timed out" in the Open () line after 30 seconds. The strange thing is the exception, even if I attach the debugger to exe. I see that the connection string is correct and everything seems fine. I cannot process additional information in the SQL Express or SQL Activity Monitor error log.

If that helps, here's what:

    System.Data.OleDb.OleDbException: Login timeout expired
   at System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr, OleDbConnection connection)
   at System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject)
   at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup)
   at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
   at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
   at System.Data.OleDb.OleDbConnection.Open()

, , , , , , , , .

+3
1

. , , : , reset , SQL Express, .. - . , , OleDb 31 , ().

.

0

Source: https://habr.com/ru/post/1747520/


All Articles