问题
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;
}
回答1:
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.
回答2:
I don't think you'll get any benefit from pooling for an access database. If performance is an issue, access is a poor choice.
回答3:
These are the connectionstring
attributes which can be used:
- All services (the default)
OLE DB Services = -1;
- All services except pooling
OLE DB Services = -2;
- All services except pooling and auto-enlistment
OLE DB Services = -4;
- All services except client cursor
OLE DB Services = -5;
- All services except client cursor and pooling
OLE DB Services = -6;
- No services
OLE DB Services = 0;
来源:https://stackoverflow.com/questions/10012627/connection-pooling-with-access-database