locked
First attempt to connect fails RRS feed

  • Question

  • I have a C# application that connects to a SQL Server Express 2005 instance. One of the testers here shuts his machine down every night and first thing in the morning when he fires up the application it fails to connect. If he tries to open it again right after that it connects. What would the failed attempt do that would fix the instance?
    Friday, May 11, 2007 1:31 PM

Answers

  • If the C# application is using User Instances, the problem is likely a timeout. Check the connection string, if it is specifiying User Instance = TRUE, then add 'Connection Timeout=60' and the problem will likely go away. The issue is that a User Instance has to be started when the application is started and depending on hardware, it can take a bit longer than the default connection time out. Once it has started, it will hang around for 60 minutes after the last connection is dropped, so the second time you run the applciation, the User Instance is running and the connection can be made within the default timeout setting.

     

    Mike

    Friday, May 11, 2007 8:42 PM
  • YOu don´t have to, depending on the machine and the workload it also could be that the database is closed again and will have to open after reconnecting. The autoclose option can be either turned off (turned on by default for Express instances) or the connection timeout can be increased as Mike pointed out.

    Jens K. Suessmeyer.

    ---
    http://www.sqlserver2005.de
    ---
    Monday, May 14, 2007 9:07 PM

All replies

  • hi,

    what is the reported exception?

    regards

    Friday, May 11, 2007 4:39 PM
  • If the C# application is using User Instances, the problem is likely a timeout. Check the connection string, if it is specifiying User Instance = TRUE, then add 'Connection Timeout=60' and the problem will likely go away. The issue is that a User Instance has to be started when the application is started and depending on hardware, it can take a bit longer than the default connection time out. Once it has started, it will hang around for 60 minutes after the last connection is dropped, so the second time you run the applciation, the User Instance is running and the connection can be made within the default timeout setting.

     

    Mike

    Friday, May 11, 2007 8:42 PM
  • The connection string doesn't have user instance in it. Should I just not be using user instances?

    Monday, May 14, 2007 1:04 PM
  • YOu don´t have to, depending on the machine and the workload it also could be that the database is closed again and will have to open after reconnecting. The autoclose option can be either turned off (turned on by default for Express instances) or the connection timeout can be increased as Mike pointed out.

    Jens K. Suessmeyer.

    ---
    http://www.sqlserver2005.de
    ---
    Monday, May 14, 2007 9:07 PM