Hey everyone!
Just wanted to ask your opinion on what is a better way to execute sql statements in a loop. First version opens and closes connection inside a loop, and the other does it once outside of it.
I have read that it is better to open and close connections immediately, but still version 1 looks like a huge overkill...
What do you think is more efficient?
VERSION 1:
var connTviDB = Server.CreateObject("ADODB.Connection"
for (i=0; i<arrMsgIDs.length; i++)
{
sqlQuery = "DELETE FROM tviMemberMessages "
sqlQuery += "WHERE messageID = " + arrMsgIDs[ i ]
connTviDB.Open(...)
connTviDB.Execute(sqlQuery)
connTviDB.Close()
Response.Write(sqlQuery + "<BR>"
}
connTviDB = null
OR
VERSION 2
var connTviDB = Server.CreateObject("ADODB.Connection"
connTviDB.Open(...)
for (i=0; i<arrMsgIDs.length; i++)
{
sqlQuery = "DELETE FROM tviMemberMessages "
sqlQuery += "WHERE messageID = " + arrMsgIDs[ i ]
connTviDB.Execute(sqlQuery)
Response.Write(sqlQuery + "<BR>"
}
connTviDB.Close()
connTviDB = null
<Dmitriy>
dbrom@crosswinds.net
Just wanted to ask your opinion on what is a better way to execute sql statements in a loop. First version opens and closes connection inside a loop, and the other does it once outside of it.
I have read that it is better to open and close connections immediately, but still version 1 looks like a huge overkill...
What do you think is more efficient?
VERSION 1:
var connTviDB = Server.CreateObject("ADODB.Connection"
for (i=0; i<arrMsgIDs.length; i++)
{
sqlQuery = "DELETE FROM tviMemberMessages "
sqlQuery += "WHERE messageID = " + arrMsgIDs[ i ]
connTviDB.Open(...)
connTviDB.Execute(sqlQuery)
connTviDB.Close()
Response.Write(sqlQuery + "<BR>"
}
connTviDB = null
OR
VERSION 2
var connTviDB = Server.CreateObject("ADODB.Connection"
connTviDB.Open(...)
for (i=0; i<arrMsgIDs.length; i++)
{
sqlQuery = "DELETE FROM tviMemberMessages "
sqlQuery += "WHERE messageID = " + arrMsgIDs[ i ]
connTviDB.Execute(sqlQuery)
Response.Write(sqlQuery + "<BR>"
}
connTviDB.Close()
connTviDB = null
<Dmitriy>
dbrom@crosswinds.net