首页 > 解决方案 > 使用经典的 ASP / Javascript ADODB 将行从一个 MS Access 数据库表复制到网络服务器上的另一个

问题描述

我们有一个托管在 godaddy 上的数据库,它为一个用经典 ASP 和一些 Javascript 构建的网站提供数据。我们有一个每日脚本,它通过覆盖刷新数据库,即。完全替换而不是增量。

这样做的缺点是,如果网站正在使用中并且数据库被锁定,那么当我们覆盖时,网站就会崩溃。

所以我们正在研究仅插入新/更新修改记录的选项 - 我们无法让下面的代码工作:

标签: javascriptadodb

解决方案


以下是一些示例代码,需要完善,但可以测试我们正在评估的场景:

<%
'
' Show Date
'
Response.Write ("Date Today    :" & Date & "<br/>")

'
' Connect to DB object 
'
sConnect = "Driver={Microsoft Access Driver (*.MDB)}; DBQ=" & Server.MapPath("/temp/propertyDB.mdb")
sConnect_tmp = "Driver={Microsoft Access Driver (*.MDB)}; DBQ=" & Server.MapPath("/temp/propertyDB_tmp.mdb")

'
' Create recordset object 
'
Set rsProperty = Server.CreateObject("ADODB.Recordset")
Set rsProperty_tmp = Server.CreateObject("ADODB.Recordset")

'
' Compose the SQL statement for the recordset.
'
sSQL = "SELECT * FROM Property ORDER BY txtRefNo"

'
' Open a recordset and move to the first record
'
rsProperty_tmp.Open sSQL, sConnect_tmp, 3
rsProperty_tmp.MoveFirst
Response.write "- The number of records to INSERT into PropertyDB is : [ " & rsProperty_tmp.RecordCount & " ] <br/>"

'
' Open a recordset and move to the first record + show record count
'
rsProperty.Open sSQL, sConnect_tmp, 3
rsProperty.MoveFirst
Response.write "- Total Number of Records before Insert =  : [ " & rsProperty.RecordCount & " ] <br/>"
rsProperty.Close

'
' Insert Into SQL 
'
sSQL ="INSERT INTO [property] SELECT distinct * FROM " & Server.MapPath("/temp/propertyDB_tmp.mdb") &".property"
rsProperty.Open sSQL,sConnect,3
Response.write "- The number of records in PropertyDB is now: [ " & rsProperty.RecordCount & " ] <br/>"  

'
' CLOSE RecordCount
'
rsProperty_tmp.Close
rsProperty.Close
Set sConnect = nothing
set sConnect_tmp = nothing
Response.Write "- Connection & Recordsets CLOSED OK"  

%>   

推荐阅读