I've written the following subroutine to "merge" two database tables. It takes two parameters, a database to copy from and a database to copy to. It cycles through the database to copy from and where there is a record which exists in the other database it edits it, and where the record does not exist in the other database, it adds it. Essentially it takes the records from the "copy from" database and fits them into the "copy to" database.
The problem is that I always get this error:
The script always fails at the same point, after processing 678 records. Does anyone know why this might be the case? Do database objects have a "shelf life"? Is there any way I can get it to process the entire table?
Code:
private sub mergeDB (newdb, olddb)
Dim dbc
dim dbc2
Dim strConn
dim strConn2
dim rs
dim rs2
strConn = "Driver={Microsoft Access Driver (*.mdb)};DBQ="& olddb
strConn2 = "Driver={Microsoft Access Driver (*.mdb)};DBQ="& newdb
Set dbc = Server.CreateObject("ADODB.Connection")
set dbc2 =server.createobject("adodb.connection")
dbc.open strConn
dbc2.open strConn2
strSQL2="SELECT * FROM parts"
set rs2=server.createobject("adodb.recordset")
rs2.open strSQL2, dbc2
rs2.movefirst
n=1
while not rs2.eof
strSQL="select * from parts where partno='" & rs2("partno") & "'"
response.write "SQL string: " & strsql & "<br>"
set rs=server.createobject("adodb.recordset")
rs.open strSQL, dbc, 3, 3
if rs.eof then
rs.addnew
for i=1 to 8
response.write rs2.fields(i).value & "<br>"
if rs2.fields(i).value<>"" then
rs.fields(i).value=rs2.fields(i).value
else
rs.fields(i).value=""
end if
next
response.write n
n=n+1
rs.update
else
while not rs.eof
for i=1 to 8
response.write rs2.fields(i).value & "<br>"
if rs2.fields(i).value<>"" then
rs.fields(i).value=rs2.fields(i).value
else
rs.fields(i).value=""
end if
next
response.write n
n=n+1
rs.update
rs.movenext
wend
end if
rs.close
set rs=nothing
rs2.movenext
wend
rs2.close
set rs2=nothing
dbc.close
set dbc=nothing
dbc2.close
set dbc2=nothing
End sub
Code:
Microsoft OLE DB Provider for ODBC Drivers error '80004005'
[Microsoft][ODBC Microsoft Access Driver] Object invalid or no longer set.
/***********/Loader.asp, line 255