我有一个程序,删除任何比我的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“)' –