3

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.

KMån
  • 9,896
  • 2
  • 31
  • 41
Francesc Castells
  • 2,692
  • 21
  • 25
  • Are you saying that when you are not debugging, the application is running from IIS? – Jay May 28 '10 at 11:29
  • No, it's a WinForms app. In other words: if I press F5 in VS it works. If I double click the exe in Windows Explorer, it fails. If I set up VS to start the exe an attach the debugger, it fails too. – Francesc Castells May 28 '10 at 11:38
  • My best guess would be that you are running out of concurrent connections. Express only allows 5 I think. If you have the IDE open as well as one or two other tools such as Management Studio you may be reaching 5. If you have something like connection pooling switched on it may be that all 5 are tied up somewhere? – Cobusve May 28 '10 at 11:38
  • @Cobusve: The exception says, *login timeout*; how could it relate to concurrent connections? – KMån May 28 '10 at 11:40
  • @Francesc: Did you check the database logs? http://social.msdn.microsoft.com/forums/en-US/adodotnetdataproviders/thread/72a12ece-62ac-4a0c-a17a-b19bbfa53998 – KMån May 28 '10 at 11:45
  • @KMan: I already followed that post. I can't see any error or clue in the SQL Server log. What I do see is that when it connects, in the log appears "spid51 Starting up database 'dbname'." and when it doesn't work, no entries are added in to log. It'd be nice to see a kind of "connection failed due to xxx". – Francesc Castells May 28 '10 at 12:09
  • @Francesc: Did you try increasing the default timeout length? – ajdams May 28 '10 at 13:05
  • Well that's funny...the default timeout is 30seconds. I set it to 60 seconds and it happened to connect after 31 seconds! I set it to 31 seconds (just for fun) and it hangs (a dead lock or something). The issue is now why debugging in VS the connection is immediate and from the exe it takes 31 seconds? – Francesc Castells May 28 '10 at 14:23

1 Answers1

0

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.

Francesc Castells
  • 2,692
  • 21
  • 25