Tutorial :OleDB connection only working when debugging



Question:

I have a C# application that connects to a named SQL Express instance on the 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 an "OleDBException: Login timeout expired" in the Open() line after 30 seconds. The strange thing is the exception happens even if I attach the debugger to the exe. I can see that the connection string is correct and everything seems fine. I can't fine any extra information in the SQL Express error log or SQL Activity Monitor either.

If it helps, here is the exception:

    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()  

I imagine that find the issue with the information I give here might be difficult, but I don't know where else to look or what other tests to do, so any ideas on what it could be or what test I could do to find out will be really appreciated.


Solution:1

I fixed it. Unfortunately I don't really know how: I deleted the output folder, reset some project references, reconfigured several things on SQL Express, restarted the machine, etc. At some point, it started working fine again. It still annoys me not being able to discover what OleDb was doing for 31 seconds when connecting, but the problem is gone now (so far).

Thanks for your help.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »