Hi,
I have an application written in calssic asp which connects to a sql server 2005 db.
I have 2 procs to open and close the db as follows
I've just discovered (sorry if this is common knowledge) that doing this (case 1)...
is exactly the same as doing this (case 2)...
So have 3 questions...
1. Am i right in thinking that since strConn is a global variable, so as long as the connection has been opened at least once, strConn is available for use in the recordset open command.
2. In case 1, am i actually opening the connection twice (or at least making the call twice) i.e once via the sub and then a second time via the recordset open method.
3. Am i right in thinking that case 2 is not good practice since the connection has not been expicitly closed after the query.
Or maybe what i am pointing out demonstrates inefficiencies in my coding. fyi, i diligently code according to case 1 but maybe i can improve this further.
Thanks in advance for any help.
I have an application written in calssic asp which connects to a sql server 2005 db.
I have 2 procs to open and close the db as follows
Code:
Dim strConn
Dim oConn
sub OpenDataConnection()
set oConn = CreateObject("ADODB.Connection")
strConn = "Provider=SQLOLEDB; Data Source = xxx; Initial Catalog = xxx; User Id = xxx; Password=xxx"
oConn.Open strConn
end sub
sub CloseDataConnection()
oConn.Close
set oConn = nothing
end sub
Code:
OpenDataConnection()
set rsID = CreateObject("ADODB.recordset")
searchPhrase = "SELECT blah"
rsID.Open searchPhrase, strConn
rsID.close
CloseDataConnection()
Code:
OpenDataConnection()
CloseDataConnection()
set rsID = CreateObject("ADODB.recordset")
searchPhrase = "SELECT blah"
rsID.Open searchPhrase, strConn
rsID.close
1. Am i right in thinking that since strConn is a global variable, so as long as the connection has been opened at least once, strConn is available for use in the recordset open command.
2. In case 1, am i actually opening the connection twice (or at least making the call twice) i.e once via the sub and then a second time via the recordset open method.
3. Am i right in thinking that case 2 is not good practice since the connection has not been expicitly closed after the query.
Or maybe what i am pointing out demonstrates inefficiencies in my coding. fyi, i diligently code according to case 1 but maybe i can improve this further.
Thanks in advance for any help.
Comment