已有22人关注
如何备份数据库?
发表在VB答疑区 2009-01-31
是否精华
版块置顶:
我在模仿贵司出版的《VB数据库系统开发案例精选》一书第7章344页的数据备份这一代码时,却提示:“无效的SQL语句”,请专家不吝赐教!,我的代码是(贵书源代码不曾改动,只是改成了连接我的数据库):
Dim StrCnn As New ADODB.Connection     '定义连接
Private Sub Command1_Click()
 CommonDialog1.Filter = "备份文件(*.mdb)|*.mdb|文本文件(*.txt)|*.txt|ALL File(*.*)|*.*"
   CommonDialog1.ShowSave
   Text1.Text = CommonDialog1.FileName
End Sub
Private Sub Command2_Click()
Command2.Enabled = False
Me.MousePointer = 11
If Text1.Text = "" Then
   MsgBox "请您选择数据库备份的路径!", 64, "提示信息"
Else
Dim connter As Integer
Dim sql, workarea(12) As String
ProgressBar1.Visible = True
ProgressBar1.Max = UBound(workarea)
ProgressBar1.Value = ProgressBar1.Min
   For connter = LBound(workarea) To UBound(workarea)
       workarea(connter) = "initial value" & connter
       ProgressBar1.Value = connter
            StrCnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\datasource\wgxxgl.mdb;Persist Security Info=False"
            sql = "backup database wgxxgl TO disk='" & Text1.Text & "'"
            StrCnn.Execute (sql)     '执行SQL语句
            StrCnn.Close
  Next connter
  ProgressBar1.Value = ProgressBar1.Min
  MsgBox "数据库备份成功!!", 64, "提示信息"
  Command2.Enabled = True
  Me.MousePointer = 0
 End If
End Sub
分享到:
精彩评论 1
Lemon
学分:0 LV1
2009-02-05
沙发
您好!

《案例精选》中所有的数据库都是SQL Server数据库,在进行备份操作时,使用的也是SQL Server的备份方法,在上述代码中您连接的是Access的数据库,因此产生错误。对于Access数据库一般采用文件复制的方法进行备份。具体方法可以参见我公司出版的其他图书
首页上一页 1 下一页尾页 1 条记录 1/1页
手机同步功能介绍
友情提示:以下图书配套资源能够实现手机同步功能
明日微信公众号
明日之星 明日之星编程特训营
客服热线(每日9:00-17:00)
400 675 1066
mingrisoft@mingrisoft.com
吉林省明日科技有限公司Copyright ©2007-2022,mingrisoft.com, All Rights Reserved长春市北湖科技开发区盛北大街3333号长春北湖科技园项目一期A10号楼四、五层
吉ICP备10002740号-2吉公网安备22010202000132经营性网站备案信息 营业执照