none
Timeout Expired when using DataContext, but not reproducible using SQL management objects RRS feed

  • Question

  • Hi all,

    I seem to be experiencing a very weird issue whereby the connection to a SQL server instance via a DataContext and connection string is returning a "timeout exipred" error. (The very one documented here http://msdn.microsoft.com/en-us/library/ms190181.aspx).

    Oddly enough, the error does not occur if i create a new ServerConnection object and connect using SMO with the exact same connection details. The issue does not occur when connecting using the same connection details using the SQL Server Management Studio.

    This issue is only occuring (thus far) on one machine (running a client Windows OS, Win 7). A second machine (running Small Business Server 2011) does not exhibit the same problem, i.e both the DataContex and SMO ServerConnection methods work as expected.

    Is this an application issue on my end, or is it most likely a problem with the configuration on the machine hosting the SQL server instance?

    Please let me know if further information is required, or if this thread is in the wrong section.

    Thanks in advance!


    Monday, July 25, 2011 12:11 PM

Answers

  • Sorry for double post, but I have some additional information.
    I get this error using a SqlConnection and then calling the Open() method on it.
    It also occurs using SQL dependency (service broker).

    It works flawlessly on every other machine.... I'm really not sure on this one? The problematic server has remote connections enabled also... so that shouldn't be an issue.

    I've added exceptions into the firewall for UDP 1434 and the sql browser service.



    Wednesday, July 27, 2011 1:18 AM

All replies

  • Hello Tom,

    Thanks for your post.

    As far as I know, right after the using block, the datacontext is released back to the connection pool.

     

    Now, if you cache a DataContext in a local module, it might go unused for a while. Then SQL Server will eventually close your connection because it's idle for too long. The next call generates the "timeout exipred" message.

     

    I'd remove the caching of the DataContext, and keep create a new DataContext for every call or query you run. Dispose them as soon as you can. There's no performance overhead in that, because the connections are cached by a highly optimized connection pool.

    I hope this can help you.

     

    Have a nice day,


    Jackie Sun [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, July 26, 2011 3:40 PM
    Moderator
  • Hey Jackie

    Thanks for your reply. It turns out I was actually caching a single DataContext - I'd read that this was bad not long after I posted my thread. The weird thing is, the timeout expired error was actually occurring during construction of the DataContext.

    Nevertheless I have since changed the application to use and release DataContext objects as quickly as possible.

    Contrary to the topic title, I've actually managed to reproduce the timeout error using SQL management studio... a few times. So perhaps there is a configuration issue or something on the server also?

    Thanks.

    Wednesday, July 27, 2011 12:31 AM
  • Sorry for double post, but I have some additional information.
    I get this error using a SqlConnection and then calling the Open() method on it.
    It also occurs using SQL dependency (service broker).

    It works flawlessly on every other machine.... I'm really not sure on this one? The problematic server has remote connections enabled also... so that shouldn't be an issue.

    I've added exceptions into the firewall for UDP 1434 and the sql browser service.



    Wednesday, July 27, 2011 1:18 AM
  • Happy to see that you did so much and make it works finally. For it works flawlessly on every other machine, I will mark your reply as answer. If you have any questions, please feel free to let me know.

     

    Have a nice day,


    Jackie Sun [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, July 27, 2011 1:59 AM
    Moderator
  • Thanks.
    I do have a question - where can I post a thread regarding the weird issue that this one machine is having?
    Also is it ok to cache a SqlConnection object?
    Wednesday, July 27, 2011 2:08 AM
  • I'm not sure about this, maybe in the ASP.NET Forum you will find what you need. Here is the link:

    http://forums.asp.net/

    Hope this can help.


    Jackie Sun [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, July 27, 2011 2:17 AM
    Moderator