正 文

用VB备份和恢复SQL Server数据库的方法


www.7dspace.com  更新日期:2005-12-2 1:59:01  七度空间


  追加数据, 采用微软ADO (ActiveX data object) 数据模型, 分别操纵SQL Server 和Access 数据对象, 追加记录数据来完成, 有以下过程块CopyDa2ta :

Private Sub copyData ()
 Set sourceCn = New adodb. Connection
 sourceCn. CursorLocation = adUseServer
 strSql =“PROVIDER = MSDASQL ; dsn = xgsdb ; uid = sa ;
 pwd = ;”
 sourceCn. Open strSql
 Set targetCn = New adodb. Connection
 targetCn. CursorLocation = adUseClient
 targetCn. Open ” PROVIDER = Microsoft. Jet. OL Edb. 3.51 ;
 Data Source = ”& tagFilName &“;”
 End If //追加新表
 For i = 0 To tabN - 1
  Set targetRst = New adodb. Recordset
  strSql = ”select 3 from ”& tabName (i)
  targetRst. Open strSql , targetCn , adOpenStatic , adLockPes2simistic , adCmdText
  Set sourceSet = New adodb. Recordset
  strSql = ”select 3 from ”& tabName (i) & strSQLApp
  sourceSet. Open strSql , sourceCn
  zdN = sourceSet. Fields. Count
  If sourceSet. EOF Then Go To hh
   sourceSet. MoveFirst
   Do While Not sourceSet. EOF
    targetRst. AddNew
    For j = 0 To zdN - 1
     If Trim (sourceSet. Fields (j) . Value) = ””Then
      targetRst. Fields (j) . Value = Null
     Else
       targetRst. Fields (j) . Value = Trim (sourceSet. Fields(j) . Value)
     End If //复制记录
    Next
    targetRst. Update
    sourceSet. MoveNext
   Loop
   recN = targetRst. RecordCount
   hh :sourceSet. Close
   Set sourceSet = Nothing
   targetRst. Close
   Set targetRst = Nothing
  Next
  targetCn. Close
  Set targetCn = Nothing
  sourceCn. Close
  Set sourceCn = Nothing
End Sub //删除链接

  其中字符数组tabName (i) 中存放需备份的各数据表名, strSQLAPP 字符串中存放对数据表的限制条件where 子句内容。

  4、数据恢复

  如果要从Access中将数据恢复到SQL Server中,方法类似,仅仅是拷贝记录的方向和以上相反,即从Access表往链接过来的SQL表中拷贝。

4页,页码:[1] [2] [3] [4] 

上一篇:使用 JAXP 1.3 的新功能验证 XML
下一篇:将曝光不足照片巧妙处理为油画效果
作者:杨梅娟 陈亚军  来源:计算机与信息技术 ( 责任编辑:7dspace )
收藏此页】【打印】【关闭
站 内 搜 索
 

热 点 导 读
特 别 推 荐