dapper-rainbow-mysql icon indicating copy to clipboard operation
dapper-rainbow-mysql copied to clipboard

你好我想用工厂的方式去操作数据库 但是如何释放数据库链接呢?

Open qingwatianya opened this issue 5 years ago • 1 comments

采用这种方式进行数据库操作: 每次CRUD都会创建1个新的数据库链接 然后不能释放 一会儿就好几百个数据库链接了 改怎么改造呢? public class DbContextFactory { public static DbContext GetDb(string connString) { DbConnection connection = new SqlConnection(connString); if (connection.State != System.Data.ConnectionState.Open) connection.Open(); DbContext dbContext = DbContext.Init(connection, 60); return dbContext; } public static DbContext Default { get { return GetDb(Config.connString); } } }

qingwatianya avatar Mar 23 '19 03:03 qingwatianya

Sorry can't understand Chinese language, based on google translate you would like to now how to dispose the connection, its just by execute

DbContext.Dispose();

when the process complete.

antonheryanto avatar Mar 23 '19 05:03 antonheryanto