dexterslab
dexterslab

Reputation: 326

Servicestack ORM db.Close() does not terminate the connection process

I have a code which demonstrates simple mysql database connection with ServiceStack ORM

var dbFactory = new OrmLiteConnectionFactory(DB_CONNECTION_STRING, MySqlDialect.Provider);
var db = dbFactory.Open();
Console.WriteLine(db.State.ToString());
db.Close();
db.Dispose();

Result

Open

However when I hit the SQL command

show full processlist;
Id          User    Host                  db       Command  Time    State   Info    Rows_sent   Rows_examined
81107052    user1   <111.21.96.32>:51120  my_db    Sleep    7       NULL    0   0
81107178    user1   localhost             my_db    Query    0       init    show full processlist   0   0
81107179    user1   localhost             my_db    Sleep    0       NULL    0   0

That process with id 81107052 is the process which started with code execution however, goes into sleep and does not terminate by db.Close(); This triggers <max_connections_reached> error with parallel application use.

So How do I close the connection process?

Upvotes: 1

Views: 630

Answers (2)

dexterslab
dexterslab

Reputation: 326

Adding Pooling=false is required in connection string

Upvotes: 0

mythz
mythz

Reputation: 143339

Just use a using statement, i.e:

using (var db = dbFactory.Open())
{
}

Some RDBMS providers will return the connection to the pool and not close it, but you won't get a too many open connections error if all connections are properly disposed.

Upvotes: 1

Related Questions