1

I'm using the Database class from webmatrix in a windows service. (And debugging in a winform causes same error)

The error I receive (after running for a while) is:

Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occured because all pooled connections were in use and max pool size was reached.

This should be solved by using using statements to make sure all connections are closed. ( as described in this good answer) But I've recently started using also the WebMatrix database class, and it does not seem to close the connections I open with it.

Question is: How to close connections created with the Database class from WebMatrix?

Using this code:

Public Shared Function GetProperty(pid As Integer, propertyName As String) As String
    Dim db = Database.Open("SSEConnectionString")
    Dim item = db.QuerySingle("select PropertyValue from eConfiguration where PID=@0 and PropertyName=@1", pid, propertyName)
    Dim retVal = item.PropertyValue
    db.Connection.Close()
    db.Close()
    Return retVal
End Function

Each time I run this code I get a new entry in my sys.sysprocesses table (and from what I've figured out, this is indicating a new connection is created and maintained)

My connectionstring looks like this:

<add name="SSEConnectionString" connectionString="Data

Source=123.45.67.890;Initial Catalog=SSE;User ID=+++;Password=+++;Connect Timeout=5;Application Name=SSE_Service" providerName="System.Data.SqlClient" />

Any idea what I'm doing wrong?

Edit: Asked a second question regarding the sysprocesses table - unsure if it helps in debugging

Thanks for any help

Edit2: Arghhhhh.... I just found what was causing the error - and it's only related to myself. I forgot to close a connection. :-(

Larsi

Community
  • 1
  • 1
Larsi
  • 4,654
  • 7
  • 46
  • 75
  • This is maybe not related with webmatrix - changed to standard ado and see same beavior, will update question when I figure out the reason for the error – Larsi Sep 12 '11 at 12:43
  • Nobody but me to blame for this - simply forgot to to a db.close deep down in my spagetti – Larsi Sep 13 '11 at 13:26

1 Answers1

0

Use:

db.Connection.Close()
db.Close()
VoidKing
  • 6,282
  • 9
  • 49
  • 81