0

As the title suggesting, I've been doing some research on the cause of this error. Then I saw this which primarily suggesting that it is most likely related to license number. However, at the very bottom there was a reply suggesting that calling dispose() for connection object would also be a solution. Is this true?

Note: we are using Entity Framework 4.0 and SQLAnywhere 16

Update: I've found this article which seems to be suggesting that calling dispose does not have any impact on user connection. Any thoughts? Thanks much!

LulalaBoss
  • 127
  • 1
  • 9
  • Pretty sure you should call dispose after you're done with the connection object or else you're going to have tons of open connections, therefore throwing this error. – Jon La Marr Aug 28 '13 at 17:32
  • 1
    You should dispose of anything that is idisposable. Better yet, do a `using` statement and it will clean itself up! – Kevin DeVoe Aug 28 '13 at 17:33

1 Answers1

0

Kevin brought up a good point in the comments. It's easiest to just put your connection in a using statement so it is automatically disposed of when not in use.

// connectionString must be set up
using (SqlConnection connection = new SqlConnection(connectionString))
{
    // Do stuff with connection to DB
}

You were wondering if Dispose needed to ever be called and if it would have an impact on user connection. Actually, the using statement calls Dispose() itself, as you can see here. "The using statement calls the Dispose method on the object in the correct way..." So, I believe your issue may be because your original way of opening/closing the connections left hanging connections. Instead, using the using statement, your connections will automatically be closed once the code leaves the block.

Jon La Marr
  • 1,358
  • 11
  • 14