Invalid operation. The connection is closed.

Answered Invalid operation. The connection is closed.

  • Monday, October 06, 2008 7:29 PM
     
     
    I'm writing a windows service, in it I execute a linq query. When I attempt to do so I get the following exception

    "Invalid operation. The connection is closed."

    My datacontext defines it's own empty constructor
    and it's own static instance as follows:

    Code Snippet

    public QueueDataContext()
    : base(ConfigurationManager.ConnectionStrings["IntegrationConnection"].ConnectionString)
    {

    }

    public static QueueDataContext Instance
    {
    get
    {
    if (_inst == null)
    {
    _inst = new QueueDataContext();
    }
    return _inst;
    }
    private static QueueDataContext _inst;

    }

    }


    The ConfigurationManager is indeed returning a connection string.

    I have never needed to manually open a connection before executing a query. Any idea what's going on here?

All Replies

  • Monday, October 06, 2008 8:46 PM
     
     Answered
    Okay apparently executing that code sample ever 100 milliseconds in a timer is what is causing the problem... oops!

    I ended up setting the timer's Enabled property to false before executing the above code, then setting it back to true when it's completed. This effectively pauses the timer.