I put this in an include file on the top of all my pages and only use it when I need to connect to the db. All I do is call the OpenDB() at the beginning of the page and CloseDB() at the end of the page. This makes sure I close and destroy all my objects. It also has the option to comment out the server I am not currently using in one file.
<%'This page should get included at the top of all files that use database connections.
dim Conn, ConnString, RS, strSQL
Function OpenDB()
'Open database connection
Set Conn = Server.CreateObject("ADODB.Connection")
'ConnString = "Provider=SQLOLEDB; Data Source=testservername; Initial Catalog=testdbname; User Id=testuser; Password=testpasswrd"
ConnString = "Provider=SQLOLEDB; Data Source=liveservername; Initial Catalog=livedbname; User Id=liveuser; Password=livepasswrd"
Conn.Open ConnString
set RS = server.CreateObject("ADODB.RecordSet")
End Function
Function CloseDB()
'Close database connection and destroy object
set RS = nothing
Conn.Close
set Conn = nothing
End Function
%>
I just thought this may help some of the newbies keep their db code clean and easy to administer. Don't forget to name it .asp just for security reasons.
<%'This page should get included at the top of all files that use database connections.
dim Conn, ConnString, RS, strSQL
Function OpenDB()
'Open database connection
Set Conn = Server.CreateObject("ADODB.Connection")
'ConnString = "Provider=SQLOLEDB; Data Source=testservername; Initial Catalog=testdbname; User Id=testuser; Password=testpasswrd"
ConnString = "Provider=SQLOLEDB; Data Source=liveservername; Initial Catalog=livedbname; User Id=liveuser; Password=livepasswrd"
Conn.Open ConnString
set RS = server.CreateObject("ADODB.RecordSet")
End Function
Function CloseDB()
'Close database connection and destroy object
set RS = nothing
Conn.Close
set Conn = nothing
End Function
%>
I just thought this may help some of the newbies keep their db code clean and easy to administer. Don't forget to name it .asp just for security reasons.