OleDbConnection,Excel和连接池的问题 [英] Problem with OleDbConnection, Excel and connection pooling

查看:354
本文介绍了OleDbConnection,Excel和连接池的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我有同样的症状,如 C#/ ASP.NET Oledb - MS Excel读取未指定的错误,但是我的我的回答似乎没有解决它。即使关闭OleDBConnection并处理它也显示相同的症状。

So, I have the same symptoms as described in C#/ASP.NET Oledb - MS Excel read "Unspecified error", but my my answer did not seem to fix it. Even always closing the OleDBConnection and disposing of it show the same symptoms.

var connectionString = string.Format("Provider=Microsoft.ACE.OLEDB.12.0; data source={0}; Extended Properties=Excel 12.0;", _excelFile);
using (var conn = new OleDbConnection(connectionString))
{
    try
    {
        DoSomething();
    }
    finally
    {
        conn.Close();
    }
}

现在我已经找到了关于连接池的以下信息:

Now I have found the following info on connection pooling:


OLE DB的.NET Framework数据提供者会自动使用OLE DB会话池进行连接。连接字符串参数可用于启用或禁用OLE DB服务,包括池。例如,以下连接字符串禁用OLE DB会话池和自动事务处理。

The .NET Framework Data Provider for OLE DB automatically pools connections using OLE DB session pooling. Connection string arguments can be used to enable or disable OLE DB services including pooling. For example, the following connection string disables OLE DB session pooling and automatic transaction enlistment.

Provider = SQLOLEDB; OLE DB Services = -4; Data Source = localhost;集成安全性= SSPI;

Provider=SQLOLEDB;OLE DB Services=-4;Data Source=localhost;Integrated Security=SSPI;

我们建议您在完成使用连接后总是关闭或处理连接,以便将连接返回到池中。未明确关闭的连接可能无法返回到池中。例如,超出范围但尚未明确关闭的连接将仅在达到最大池大小并且连接仍然有效时才会返回到连接池。

We recommend that you always close or dispose of a connection when you are finished using it in order to return the connection to the pool. Connections that are not explicitly closed may not get returned to the pool. For example, a connection that has gone out of scope but that has not been explicitly closed will only be returned to the connection pool if the maximum pool size has been reached and the connection is still valid.

(来源: http ://msdn.microsoft.com/en-us/library/ms254502.aspx

什么是连接字符串属性 OLE DB服务,什么是 -4

What is the connection string property OLE DB SERVICES and what is a value of -4?

推荐答案

如果我明白你的问题,你想知道什么意思连接字符串属性 OLE DB Services = -4

If I understand correct your question you want to know what means the connection string property OLE DB Services=-4.

您可以在 here 找到相应的文档,此处 here 。我希望信息是你需要的。如果你想玩 DBPROPVAL_OS_AGR_AFTERSESSION 属性,它的值为8(见oledb.h)。

You can find the corresponding documentation here, here and here. I hope the information is what you need. If you want play with DBPROPVAL_OS_AGR_AFTERSESSION property it has the value 8 (see oledb.h).

这篇关于OleDbConnection,Excel和连接池的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆