Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
OleDB锁复制.NET MS访问_.net_Vb.net_Ms Access_Oledb - Fatal编程技术网

OleDB锁复制.NET MS访问

OleDB锁复制.NET MS访问,.net,vb.net,ms-access,oledb,.net,Vb.net,Ms Access,Oledb,我们正在从MS Access迁移到现代DBMS的过程中,但与此同时,我遇到了一个我无法找到解决方案或解释的问题 通常,打开OleDBConnection会生成一个锁文件,该文件在池中的最后一个连接关闭后挂起1分钟。如果您检查这个文件,它会提供一些关于锁定过程的信息,等等。通常(在我们代码的所有其他部分中),这只会在锁定文件中生成一个条目,而不管在同一个过程中打开和关闭了多少次连接,非常好 我使用完全相同的连接字符串开发了一些新功能,它似乎为每个连接在锁文件中建立了一个新条目。open()。我已经

我们正在从MS Access迁移到现代DBMS的过程中,但与此同时,我遇到了一个我无法找到解决方案或解释的问题

通常,打开OleDBConnection会生成一个锁文件,该文件在池中的最后一个连接关闭后挂起1分钟。如果您检查这个文件,它会提供一些关于锁定过程的信息,等等。通常(在我们代码的所有其他部分中),这只会在锁定文件中生成一个条目,而不管在同一个过程中打开和关闭了多少次连接,非常好

我使用完全相同的连接字符串开发了一些新功能,它似乎为每个连接在锁文件中建立了一个新条目。open()。我已经确保每个方法的finally块中的所有资源都已关闭。更糟糕的是,如果我重新加载页面,它会生成一个附加集,直到达到255个打开的连接/锁的硬限制

我在这方面和其他许多方面所能看到的唯一区别是,我在到达finally块之前加载子对象。以下模式持续下降约3个水平。我正在加载一个模板来构建一个数据输入表单,所以我并不十分关心效率

有没有人在其ldb/laccdb文件中遇到过相同条目的组合? 谢谢

Provider=Microsoft.ACE.OLEDB.12.0;数据源='…\db.accdb';持久安全信息=False;OLE DB服务=-1;
...
Public将函数加载(ByVal DB_ID作为整数)重写为布尔值
作为OLEDB连接的Dim连接
连接=新的OLEDB连接(connStr)
将读卡器变暗为OleDbDataReader=无
尝试
Dim loadCMD作为新的OleDbCommand(String.Format(“SELECT*FROM{0},其中ID=@db_ID”,tableName),连接)
loadCMD.Parameters.AddWithValue(“@db\u ID”,db\u ID)
connection.Open()
reader=loadCMD.ExecuteReader()
如果是reader.Read(),则
ID=GetNullSafeValue(reader(Schema.FormSections.ID)、GetType(Integer)、failure)
FormID=GetNullSafeValue(读卡器(Schema.FormSections.FormID)、GetType(整数)、失败)
SectionTitle=GetNullSafeValue(读取器(Schema.FormSections.SectionTitle),GetType(字符串))
Expanded=GetNullSafeValue(reader(Schema.FormSections.Expanded),GetType(Boolean))
ServiceURL=GetNullSafeValue(读取器(Schema.FormSections.ServiceURL),GetType(字符串))
SectionOrder=GetNullSafeValue(读取器(Schema.FormSections.SectionOrder)、GetType(整数)、失败)
Rows=FormRow.loadAllForSection(ID,配置)
返回真值
如果结束
特例
异常处理程序(例如,配置)
最后
如果读者不是什么都不是
reader.Close()
如果结束
连接。关闭()
结束尝试
返回错误
端函数
...
公共共享函数loadAllForSection(ByVal db_SectionID为整数,ByVal cfg为ReportManager配置)作为列表(FormRow)
Dim retList作为新列表(FormRow的)
作为OLEDB连接的Dim连接
连接=新的OLEDB连接(cfg.RM_LabConfig.connString)
将读卡器变暗为OleDbDataReader=无
尝试
Dim loadAll作为新的OleDbCommand(String.Format(“从{0}中选择ID,其中SectionID=@db_sID ORDER BY RowNumber ASC”,cfg.RM_LabConfig.FormRowsTable),连接)
loadAll.Parameters.AddWithValue(“@db\u-sID”,db\u-SectionID)
connection.Open()
reader=loadAll.ExecuteReader()
边读边读
将此行调整为新窗体行(cfg)
load(GetNullSafeValue(reader(Schema.FormRows.ID)、GetType(Integer)、failure))
如果thisRow.ID失败,则
retList.Add(此行)
如果结束
结束时
特例
例外处理程序(例如,cfg)
最后
如果读者不是什么都不是
reader.Close()
如果结束
连接。关闭()
结束尝试
返回列表
端函数

我对此不确定,但我正试图回答您的问题


尝试在Try块中关闭连接,并在finally块中检查连接是否已打开。如果已经打开,则将其关闭

通过实验,我已经能够确定锁的建立是由于在外部调用释放连接之前在其他函数调用内部创建新连接造成的

解决方案是重写它,确保在进入较低级别之前关闭连接


唯一无法解释的是,为什么重新运行查询会进一步构建列表。连接最终被关闭,因此我希望它下次使用这些插槽。

谢谢您的回复,但这似乎没有效果。
Provider=Microsoft.ACE.OLEDB.12.0;Data Source='...\db.accdb';Persist Security Info=False;OLE DB Services=-1;
...
Public Overrides Function load(ByVal DB_ID As Integer) As Boolean
        Dim connection As OleDbConnection
        connection = New OleDbConnection(connStr)
        Dim reader As OleDbDataReader = Nothing
        Try
            Dim loadCMD As New OleDbCommand(String.Format("SELECT * FROM {0} WHERE ID = @db_ID", tableName), connection)
            loadCMD.Parameters.AddWithValue("@db_ID", DB_ID)
            connection.Open()
            reader = loadCMD.ExecuteReader()
            If reader.Read() Then
                ID = GetNullSafeValue(reader(Schema.FormSections.ID), GetType(Integer), failure)
                FormID = GetNullSafeValue(reader(Schema.FormSections.FormID), GetType(Integer), failure)
                SectionTitle = GetNullSafeValue(reader(Schema.FormSections.SectionTitle), GetType(String))
                Expanded = GetNullSafeValue(reader(Schema.FormSections.Expanded), GetType(Boolean))
                ServiceURL = GetNullSafeValue(reader(Schema.FormSections.ServiceURL), GetType(String))
                SectionOrder = GetNullSafeValue(reader(Schema.FormSections.SectionOrder), GetType(Integer), failure)
                Rows = FormRow.loadAllForSection(ID, config)
                Return True
            End If
        Catch ex As Exception
            ExceptionHandler(ex, config)
        Finally
            If reader IsNot Nothing Then
                reader.Close()
            End If
            connection.Close()
        End Try
        Return False
    End Function
...
Public Shared Function loadAllForSection(ByVal db_SectionID As Integer, ByVal cfg As ReportManagerConfiguration) As List(Of FormRow)
    Dim retList As New List(Of FormRow)
    Dim connection As OleDbConnection
    connection = New OleDbConnection(cfg.RM_LabConfig.connString)
    Dim reader As OleDbDataReader = Nothing
    Try
        Dim loadAll As New OleDbCommand(String.Format("SELECT ID FROM {0} WHERE SectionID = @db_sID ORDER BY RowNumber ASC", cfg.RM_LabConfig.FormRowsTable), connection)
        loadAll.Parameters.AddWithValue("@db_sID", db_SectionID)
        connection.Open()
        reader = loadAll.ExecuteReader()
        While reader.Read
            Dim thisRow As New FormRow(cfg)
            thisRow.load(GetNullSafeValue(reader(Schema.FormRows.ID), GetType(Integer), failure))
            If thisRow.ID <> failure Then
                retList.Add(thisRow)
            End If
        End While
    Catch ex As Exception
        ExceptionHandler(ex, cfg)
    Finally
        If reader IsNot Nothing Then
            reader.Close()
        End If
        connection.Close()
    End Try
    Return retList
End Function