Connection Pooling with Access database

耗尽温柔 提交于 2020-01-14 09:07:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!