有一个数据库文件mydata.mdb. 我在VB6中如何将这个数据库文件另存(备份)?
Dim databasename As String
CommonDialog1.ShowSave
databasename = CommonDialog1.FileName
FileCopy dataname, databasename
我用以上简单的方法无法备份文件.
Dim databasename As String
CommonDialog1.ShowSave
databasename = CommonDialog1.FileName
FileCopy dataname, databasename
我用以上简单的方法无法备份文件.
SourceFile = "c:\test.txt" ' 指定源文件名。
DestinationFile = "d:\test.txt" ' 指定目的文件名。
FileCopy SourceFile, DestinationFile ' 将源文件的内容复制到目的文件中
这样是可以的啊,
这个好象是要定义的
Dim fso As New FileSystemObject
===================================================
不懂啊! 俺不大明白怎么备份数据库. 求教
'备份e:\db1.mdb 为e:\db2.mdb
Private Sub Command1_Click()
Dim mfile As String, mfile2 As String
mfile = "e:\db1.mdb"
mfile2 = "e:\db2.mdb"
Dim buff() As Byte
Dim i As Long
i = FileLen(mfile)
ReDim buff(i - 1)
Open mfile For Binary As #1
Get #1, , buff
Close #1
Open mfile2 For Binary As #1
Put #1, , buff
Close #1
MsgBox "ok"
End Sub
===================================================
不懂啊! 俺不大明白怎么备份数据库. 求教
另外. 我搜了下网上的代码.
Dim cn As ADODB.Connection
Dim fso As New FileSystemObject
Dim fldr As FolderDim backFile As String
Dim NowTime As String
Dim sql1 As String
Dim buff As String
If fso.FolderExists(App.Path & "\BackUp") = False Then
Set fldr = fso.CreateFolder(App.Path & "\BackUp")
End IfNowTime = Format(Now, "yyyy-mm-dd_hh-mm-ss")
backFile = "1234" & NowTime
sql1 = "BACKUP DATABASE [1234] TO disk='" & App.Path & "\BackUP\" & backFile & "'"cn.Execute (sql1)
执行后编译出错.
用户定义类型未定义.
光标停在Dim fso As New FileSystemObject行.
应该在工程中引用哪个?俺不大明白. 再次求教
这是我用的备份代码
'单机版备份
If gcnLeaguers.State = 1 Then '先关闭数据库连接
gcnLeaguers.Close
Set gcnLeaguers = Nothing
End If
FileCopy SourceFile, DestinationFile ' 将源文件的内容复制到目的文件中。
MsgBox "数据库已备份完毕!", vbOKOnly, "系统提示"
Set gcnLeaguers = New ADODB.Connection '再打开数据库连接
If (Right(App.Path, 1) <> "\") Then
gsCurConnectedMdb = App.Path & "\longtan.mdb"
Else
gsCurConnectedMdb = App.Path & "longtan.mdb"
End If
gcnLeaguers.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & gsCurConnectedMdb & ";Persist Security Info=False" '未加密码
gcnLeaguers.ConnectionTimeout = 5
gcnLeaguers.Open
Microsoft Scriptina Runtime主要是干什么用的?
我用了您的代码试了备份功能.
If gcnLeaguers.State = 1 Then '先关闭数据库连接
gcnLeaguers.Close
Set gcnLeaguers = Nothing
End If
FileCopy SourceFile, DestinationFile ' 将源文件的内容复制到目的文件中。
MsgBox "数据库已备份完毕!", vbOKOnly, "系统提示"
结果还是无法备份.真是郁闷. 试了好几个不同的版本都不行.
1。关闭数据库连接
2。将mdb文件从源地址复制到目的地址
3。重新连接数据库你不能备份到底是怎么不能备份,我这有一个拷贝文件的代码,你可以试试单纯复制一个文件能否成功
Dim SourceFile, DestinationFile
SourceFile = "c:\test.txt" ' 指定源文件名。
DestinationFile = "d:\test.txt" ' 指定目的文件名。
FileCopy SourceFile, DestinationFile ' 将源文件的内容复制到目的文件中
这个我测试过,是可以复制的
Dim buff() As Byte, i%
i = FileLen(SourceFile)
ReDim buff(i - 1)
Open SourceFile For Binary As #1
Get #1, , buff
Close #1
Open DestinationFile For Binary As #1
Put #1, , buff
Close #1
MsgBox "完成数据库备份!"
End Sub
Private Sub cmdBackup_Click()
Dim backFile As String
Dim NowTime As String If Dir(App.Path & "\BackUp", vbDirectory) <> "" Then
NowTime = Format(Now, "yyyy-mm-dd_hh-mm-ss")
backFile = "1234" & NowTime
BackUp App.Path & "\1234.mdb", backFile
Else
MsgBox "文件夹不存在!"
End If
End Sub
BackUp App.Path & "\1234.mdb", backFile
把上面那句改为
BackUp App.Path & "\1234.mdb", App.Path & "\BackUp\" & backFile
我采用您的二进制备份方式. 现在还有个小问题.就是如果另存到同名的数据库.怎么检测的到备份数据库已存在?
Dim fs As ObjectDstFilePath = "\\gq\d$\bak\2005-08-11" '目标文件路径
Set fs = CreateObject("Scripting.FileSystemObject") '创建文件系统对象
If fs.FileExists(DstFilePath) Then
If MsgBox("该文件已存在,覆盖吗?", vbCritical + vbOKCancel, "提示") = vbCancel Then End
fs.DeleteFile DstFilePath, True
End If fs.CopyFile "D:\新建文件夹 (3)\龙谭交换机\一级报警软件系统7.28SQL版\BACKUP\Net\2005-08-11", DstFilePath '复制文件到目标文件夹
----------------------------------------
If Dir(App.Path & "\BackUp\" & backFile)<>"" Then
MsgBox "备份数据库已经存在!"
End If