Gordon Gordon - 5 months ago 10x
MySQL Question

How to automatically close mysql connection in ServiceStack ormlite

I used ServiceStack OrmLite to access AWS MySQL , when a API request returned the data. There are lots of MySql connections in sleep state.

How to close those db connections when ending a request ?

public object Get(GetCustomer request)
return Db.SingleById<Customer>(request.Id);

I hosted API in IIS.

ServiceStack and ServiceStack.OrmLite is 4.0.56

MySQL is from AWS RDS, database engine version is 5.6.21

MySQL.Data is 6.9.8


I found the reason. I register some interface without scope. the correct method is:

container.RegisterAutoWiredType(x, ReuseScope.Request)

Default reuse scope is ReuseScope.None.