Visualizzazione dei risultati da 1 a 2 su 2
  1. #1

    evitare apertura chiusura continua del db

    Ciao a tutti,
    ho questo codice
    codice:
     <%
    			Set objConn = Server.CreateObject("ADODB.Connection")
    
    '*************************************
    ' CHANGE THE FOLLWING DATA SOURCE
    ' PATH TO POINT TO WHERE YOU HAVE
    '*************************************
    strCon = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("/mdb-database/studenti.mdb")
    objConn.connectionstring = strCon
    objConn.Open
    pippo=temp+meseanno
    Set objRS = Server.CreateObject("ADODB.Recordset")
    '******************CREO RS PER L'INSERIMENTO DELLE DATE*****************'
    				' Set the SQL Statement to get the information from the database
    				strSQL = "SELECT * FROM lezioni WHERE studente = '" & user & "' AND DATA= '" & pippo & "' AND ORA= '"& orario &"' "
    				' Open the Database
    				objRS.Open strSQL, objConn
    			
    			
    			
    			
    				if not objRS.eof THEN%>
              <tr>
    			<td height=50 align="center" class="blogEntry1ora"> 18.00 
     <%=objRS("materia")%>
    			
    			<%ELSE%>
    			<tr>
    			<td class="blogEntry" height=50>
    			<%end if
    			objConn.close%>
    			</td>
    		</tr>
    		
    		
    		
    		
    		 <%
    			Set objConn = Server.CreateObject("ADODB.Connection")
    
    '*************************************
    ' CHANGE THE FOLLWING DATA SOURCE
    ' PATH TO POINT TO WHERE YOU HAVE
    '*************************************
    strCon = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("/mdb-database/studenti.mdb")
    objConn.connectionstring = strCon
    objConn.Open
    pippo=temp+meseanno
    Set objRS = Server.CreateObject("ADODB.Recordset")
    '******************CREO RS PER L'INSERIMENTO DELLE DATE*****************'
    				' Set the SQL Statement to get the information from the database
    				strSQL = "SELECT * FROM lezioni WHERE studente = '" & user & "' AND DATA= '" & pippo & "' AND ORA= '"& orario2 &"' "
    				' Open the Database
    				objRS.Open strSQL, objConn
    			
    			
    			
    			
    				if not objRS.eof THEN%>
              <tr>
    			<td height=50 align="center" class="blogEntry2ora"> 19.00 
     <%=objRS("materia")%>
    			
    			<%ELSE%>
    			<tr>
    			<td class="blogEntry" height=50>
    			<%end if
    			objConn.close%>
    			</td>
    		</tr>
    		
    		
    		
    		 <%
    			Set objConn = Server.CreateObject("ADODB.Connection")
    
    '*************************************
    ' CHANGE THE FOLLWING DATA SOURCE
    ' PATH TO POINT TO WHERE YOU HAVE
    '*************************************
    strCon = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("/mdb-database/studenti.mdb")
    objConn.connectionstring = strCon
    objConn.Open
    pippo=temp+meseanno
    Set objRS = Server.CreateObject("ADODB.Recordset")
    '******************CREO RS PER L'INSERIMENTO DELLE DATE*****************'
    				' Set the SQL Statement to get the information from the database
    				strSQL = "SELECT * FROM lezioni WHERE studente = '" & user & "' AND DATA= '" & pippo & "' AND ORA= '"& orario3 &"' "
    				' Open the Database
    				objRS.Open strSQL, objConn
    			
    			
    			
    			
    				if not objRS.eof THEN%>
              <tr>
    			<td height=50 align="center" class="blogEntry3ora"> 20.00 
     <%=objRS("materia")%>
    			
    			<%ELSE%>
    			<tr>
    			<td class="blogEntry" height=50>
    			<%end if
    			objConn.close%>
    			</td>
    		</tr>
    Il problema sta nel fatto che questo codice è all'interno di ciclo while di 30 salti.
    Se lascio questo codice ottengo apri e chiudi db 90 volte e non mi sembra bello.
    Come posso evitare l'apertura e la chiusura continua.
    Ho provato a fare un apri objconn all'inizio e un objconn.close alla fine. Ma dopo mi da errore su objRs
    Come devo fare?

  2. #2
    in linea di massima aprire e chiuder non fa male. detto questo, la cosa può essere ottimizzata, ad esempio

    open
    insert
    insert
    insert
    insert
    close

    è ovviamente meglio di

    open
    insert
    close
    open
    insert
    close
    open
    insert
    close
    open
    insert
    close

    se tu sei all'interno di un ciclo puoi fare

    open
    for x=1 to 1000
    insert
    next
    close

    questa la logica: adattala al tuo caso

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2026 vBulletin Solutions, Inc. All rights reserved.