我們正在從MS Access遷移到現代DBMS,但同時我遇到了一個我找不到解決方案或解釋的問題。OleDB鎖定重複.NET MS Access
通常情況下,打開OleDBConnection會生成一個鎖定文件,該文件在池關閉後的最後一次連接後掛起1分鐘。如果你檢查這個文件,它會給出一些關於鎖定過程的信息,等等。通常(在我們的代碼的所有其他部分),這隻會在鎖文件中產生一個條目,而不管連接打開和關閉多少次同樣的過程,很好。
我已經開發了一些新的功能,使用完全相同的連接字符串似乎在每個connection.open()的這個鎖文件中建立一個新的條目。我已經確定所有資源都在每個方法的finally塊中關閉。更糟糕的是,如果我重新加載頁面,它會產生一個額外的設置,直到達到255個打開的連接/鎖的硬限制。
我可以看到在這個和其他許多領域唯一的區別是我加載子對象之前到達finally塊。以下模式繼續下降約3個級別。我正在加載模板來構建數據輸入表單,所以我不關心效率問題。
有沒有人在他們的ldb/laccdb文件中遇到過這種相同條目的構建? 謝謝
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
感謝您的回覆,但這似乎沒有效果。 – IKx2cf