我有一個程序,刪除任何比我的Access2010數據庫中的某個日期早的數據,然後壓縮數據庫。該程序的刪除部分工作正常,但我收到錯誤「無效的參數」當我試圖緊湊之後。這裏是我的代碼看起來像:壓縮數據庫錯誤
'Deleting anything older than chosen before databse is compacted.
Dim DateA As Date = Date.Now
Dim DateB As String
Dim ConnString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Forte\Fortedb.accdb"
Dim ParentCNN = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Forte\Fortedb.accdb"
Dim CloneCNN = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Forte\Temp.accdb"
Dim cnn As New OleDbConnection(ConnString)
Dim sql As String
'Formatting the date to make it 7 days into the past.
DateB = Format(DateA.AddDays(ApplicationPropertiesWindow.DeleteFilebox.SelectedIndex + 1), "MM/dd/yy")
cnn.Open()
'Delete everything from b_forte where proddate is less than date - chosen time.
sql = "DELETE * FROM b_forte WHERE ProdDate < #" & DateB & "#"
Dim Command = New OleDb.OleDbCommand(sql, cnn)
Command.ExecuteNonQuery()
cnn.Close()
'Compacting the databse
Try
Dim JrO As New JRO.JetEngine
cnn.Open()
JrO.CompactDatabase(ParentCNN, CloneCNN)
If System.IO.File.Exists("C:\Forte\Temp.accdb") Then
System.IO.File.Delete("C:\Forte\Fortedb.accdb")
Rename("C:\Forte\Temp.accdb", "C:\Forte\Fortedb.accdb")
Logging("Database compacted.")
cnn.Close()
End If
Catch ex As Exception
MainTextBox.AppendText(Environment.NewLine & "Database Compression Failure :" & vbCr & ex.Message)
End Try
我使用vb.net 2010和訪問2010數據庫上沒有密碼。
我將如何去使他們成爲連接信息? –
@ChaseErnst我不明白你在問什麼。 「CompactDatabase」的第一個參數應該是「C:\ Forte \ Fortedb.accdb」(沒有連接細節)。您可以爲此創建一個新的字符串變量,另一個用於「C:\ Forte \ Temp.accdb」。 –
我試過我把 'JrO.CompactDatabase(「Provider = Microsoft.ACE.OLEDB.12.0; Data Source = C:\ Forte \ Fortedb.accdb」,「Provider = Microsoft.ACE.OLEDB.12.0; Data源= C:\復\ Temp.accdb「)' –