Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
qingwatianya opened this issue Mar 23, 2019 · 1 comment

Comments

@qingwatianya
Copy link

采用这种方式进行数据库操作:
每次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); }
}
}

@antonheryanto
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants