问题描述
我有一个应用程序,它从Access DATABSE频繁读取数据时,是有什么办法可以使用连接池
我打开DATABSE方法: - ?
私人布尔OpenDatabaseConnection(字符串的databaseName)
{
试
{
字符串的connectionString =供应商= Microsoft.Jet.OLEDB.4.0;+
数据源=+ +的databaseName;;
settingsDbConn =新的OleDbConnection(的connectionString);
settingsDbConn.Open();
}
赶上(例外)
{
返回FALSE;
}
返回真;
}
我同意的意见@sll但是,回答你的问题,那么这个字符串添加到您的连接字符串
OLE DB服务= -1
这将迫使连接使用Jet OLEDB提供程序池。结果
但是测试使用和不使用此设置你的应用程序的性能。结果
的差可以忽略不计。
和,与此设置,rembember总是返回与con.Close将其关闭或封装在使用
语句的连接的连接到连接池。
看你上面的代码,我会很小心。
I have an application which reads data from an Access databse frequently, is there any way to use connection pooling?
My Open Databse method:-
private bool OpenDatabaseConnection(string databaseName)
{
try
{
string connectionString = "Provider = Microsoft.Jet.OLEDB.4.0; " +
"Data Source = " + databaseName + ";";
settingsDbConn = new OleDbConnection(connectionString);
settingsDbConn.Open();
}
catch (Exception)
{
return false;
}
return true;
}
I concur with the comment of @sll but, to answer your question, then add this string to your connection string
OLE DB Services=-1
This will force the connection pooling with JET OleDB provider.
However test the performance of your app with and without this setting.
The difference should be negligible.And, with this setting, rembember to ALWAYS return the connection to the connection pool closing it with con.Close or encapsulating your connection in a using
statement.
Looking at your code above I will be very careful.
这篇关于与Access数据库连接池的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!