OleDbConnection处置速度非常慢(2s) [英] OleDbConnection Dispose very slow (2s)
问题描述
我在OleDbConnection访问同一个网络中Windows共享上的.mdb文件时遇到问题.当将其放置在使用部分的末端时,需要2秒钟以上的时间.打开连接并执行查询或填充DataTable最多需要50毫秒.
I have a problem with a OleDbConnection accessing a .mdb File on a Windows share in the same network. When it gets disposed at the end of the using part, it needs more than 2 seconds for that. Opening the connection and executing the query or filling the DataTable only needs up to 50ms.
那是我的代码:
private const string DbStConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;data source=\\master\db\datenezpz2004\dbST.mdb";
private const string DbStConnectionStringIp = @"Provider=Microsoft.ACE.OLEDB.12.0;data source=\\192.168.254.10\db\datenezpz2004\dbST.mdb";
using(var connection = new OleDbConnection())
{
//Die richtige Verbindungszueichenfolge finden
connection.ConnectionString = DbStConnectionString;
try
{
connection.Open();
}
catch(OleDbException)
{
connection.ConnectionString = DbStConnectionStringIp;
connection.Open();
}
//Command ausführen
const string query = "SELECT ST.idst, FName FROM ST WHERE (((ST.Status) = True) AND ((ST.IDArt) = 11))"; // AND ((ST.Fname) LIKE '%{username}%');";
using(var command = new OleDbCommand(query, connection))
{
using(var adapter = new OleDbDataAdapter(command))
{
adapter.Fill(employees);
}
}
//From Here
}
//To Here => 2 seconds
基本上,从这里"到到这里"是该代码中最耗时的部分.你有一个主意,为什么这么慢?
Basically "From Here " to "To Here" is the most time consuming part of the Code. Do you have an Idea, why it's so slow?
推荐答案
我也遇到了这个问题,除了性能甚至更差(调用Dispose大约需要20秒).一个相关问题的建议解决了该问题:在连接字符串中添加以下内容:
I also had this issue, except the performance was even worse (around 20 seconds to call Dispose). A suggestion from a related question resolved the issue: adding the following to the connection string:
OLE DB Services=-1;
这篇关于OleDbConnection处置速度非常慢(2s)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!