Salve.
Attualmente quando mi connetto al db access utilizzo le routine che ho postato sotto.
Tutto funziona bene tranne quando avvio il debug.
Infatti quando lancio il debug con visual studio mi da l'errore di connessione dicendo che l'operazione non è consentita perchè l'oggetto e chiuso.
perchè ?![]()
E' possibile ottimizzare il codice che ho scritto ?
Grazie mille
![]()
function Execute_SQL(sSQL)
On Error Resume next
dim sPathRoot,dicReturn,Conn,dicSQL,rs
set dicReturn = Server.CreateObject("Scripting.Dictionary")
sPathRoot = mid(Request.ServerVariables("PATH_INFO"),1,instr(2 ,Request.ServerVariables("PATH_INFO"),"/"))
set Conn = Server.CreateObject("ADODB.Connection")
set rs = server.CreateObject ("ADODB.Recordset")
set dicSQL = Server.CreateObject("Scripting.Dictionary")
Conn.CommandTimeout = 40
Conn.ConnectionTimeout =40
Conn.CursorLocation = 3
Conn.ConnectionString ="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(sPathRoot & "mdb-database/dati.mdb") & ";Persist Security Info=False"
Conn.Open
set rs = Conn.Execute(sSQL)
set rs.ActiveConnection = Nothing
if err.number = 0 then
dicSQL.Add "OK",rs
set Conn = Nothing
else
dicSQL.Add "KO", Array(Err.Number, Err.Description, Err.Source)
end if
Conn.Close
set Execute_SQL = dicSQL
set rs=nothing
set dicReturn=nothing
set Conn=nothing
set dicSQL=nothing
end function
sub Crea_Elenco()
dim sNome,sOpt,sSql
sSql="SELECT * FROM Anagrafica"
set DicReturn = Execute_SQL(sSql)
if dicReturn.Exists("KO") then
set dicADOError = DicReturn
Err.Raise 1000
else
set rs= dicReturn("OK")
do while not rs.EOF
..........
.........
rs.MoveNext
loop
Response.Write " //--></script>"
end if
end sub
Crea_Elenco()

Rispondi quotando
