Friday, June 27, 2008

Invalid attempt to call MetaData when reader is closed

I'm using LINQ to SQL to write information at a rapid rate to the same table via calls to a web page. At the same time there is a web service providing results from that table. So far the best info I've found on this lies here: http://blogs.msdn.com/angelsb/archive/2004/09/07/226597.aspx

  • Invalid attempt to call MetaData when reader is closed

However, this looks like it's going to be a hard problem to solve.

Need to try adding the following to my connection string declaration:

MultipleActiveResultSets=true

Subsequently hit this error as well:

  • There is already an open DataReader associated with this Command which must be closed first.

Reason given in this forum post was: This is due to a change in the default setting for MARs.  It used to be on by default and we changed it to off by default post RC1.  So just change your connection string to add it back (add MultipleActiveResultSets=True to connection string).

MARS stands for Multiple Active Result Sets.

Not sure what I'm doing with this data base at the moment, plenty of errors that need investigating:

  • ExecuteNonQuery requires an open and available Connection. The connection's current state is closed.
  • A transport-level error has occurred when receiving results from the server. (provider: Session Provider, error: 18 - Connection has been closed by peer)
  • A severe error occurred on the current command.  The results, if any, should be discarded.
  • A transport-level error has occurred when receiving results from the server. (provider: Shared Memory Provider, error: 0 - No process is on the other end of the pipe.)

3 comments:

  1. Did you ever solve it, and how? Seem to have the same problem.
    // Tobias

    ReplyDelete
  2. If I remember correctly it was because I had setup the functions in the DB class as static functions and was not locking (synchronizing) each call.
    The bad solution to the problem was to wrap each call inside the solution with a lock(lockObj) etc.
    The good solution was to change the functions from static to instance methods and use a using statement around the DataContext. This is ultimately what I did.

    ReplyDelete
  3. Hi,
    I'm interested by your solution. Can you provide a example of this solution please ? When you say "use a using statement around the DataContext"... i'm not sure to understand...
    Thanks !

    ReplyDelete