I'm having trouble deleting a temporary table that I create via ADO from an Active Server Page (using VB Script).
There appears to be some kind of timing issue.
If I DROP my table immediately after creating the structure, there's no problem.
If I open a recordset based on the table, I have to close the connection and the recordset and wait **several minutes** before DROPping the table via ADO.
I can drop the table almost immediately I move to another page in the browser, and attempt to drop the table twice - the first time fails, but the second attempt always works.
I must be doing *something* wrong! (I'm pretty much a newbie at this ADO/ASP stuff).
Thanks for any help!!!
This is the gist of the code
** Here is the constant that contains most of my connect info
' SourceDb=
Const dcVFPdbcConnStr = "Driver={Microsoft Visual FoxPro Driver}; SourceType=DBC; SourceDb="
***********************************************************
on error resume next
Dim strTmpFile, intLen, rsTempTable, SQLCREATE, SQLIns, RmConn
strTmpFile = GetTempFileName
set RmConn = server.createobject("ADODB.Connection"
'Establish a connection to the dbc
'Driver={Microsoft Visual FoxPro driver};SourceType=DBC;SourceDb=
RmConn.open dcVFPdbcConnStr & Server.MapPath("data\mydb.dbc")
set rsTempTable= server.CreateObject("ADODB.recordset")
' Generate create table string
SQLCREATE = "CREATE TABLE " & strTmpFile & " ( myfltKeys C(17))"
' Create the empty table by running the query on the database
rsTempTable.Open SQLCREATE, RmConn
' If I drop it here, it's ok
' Open the temp table
rsTempTable.Open strTmpFile, RmConn, adOpenDynamic, adLockPessimistic, adCmdTable
' This is where it won't let go - after opening it Dynamic with pessimistic record locking (I've tried other configurations)
' Do everything I can think of to release this connection/recordset
If rsTempTable.state = adStateOpen then
rsTempTable.close
rsTempTable.CursorType = adOpenDynamic
rsTempTable.LockType = adLockReadOnly
end if
' Close that connection
If RmConn.state = adStateOpen then
RmConn.close
end if
set rsTempTable = nothing
set RmConn = nothing
' Drop the Connection
'' I then run this next code from a different web page
' This first attempt fails
' remove the temp table created
Response.Write "first try
"
Call RemoveTempTable(strTmpFile)
' this second attempt works
Response.Write "second try
"
Call RemoveTempTable(strTmpFile)
'*******************************
Sub RemoveTempTable(ByVal strTmpFile)
'*******************************
' Function to remove a temporary Table on the server
' returns the true/false - the success of the removal of the table
on error resume next
Dim SQLDrop, RmConn
set RmConn = server.createobject("ADODB.Connection")
're-Establish a connection to the dbc
'Driver={Microsoft Visual FoxPro Driver};SourceType=DBC;SourceDb=
RmConn.open dcVFPdbcConnStr & Server.MapPath("data\mydb.dbc")
' Generate DROP table string
SQLDrop = "DROP TABLE "& strTmpFile
'Use the Execute method to issue a SQL query to drop the table.
RmConn.Execute SQLDrop,,adCmdText + adExecuteNoRecords
If RmConn.Errors.Count > 0 then
' try again - file in use
Response.Write ("Try again you loser ")
else
Response.Write ("Success. WoooHooo!!!!!!!!!!!!")
end if
RmConn.close
set RmConn = nothing
End Sub' RemoveTempTable