View Full Version : How to use function include file for the connection to database

Why liew
08-12-2005, 02:26 PM
hi i am a student now doing the system and facing the pobrem for the connection to database.

because now i am usung the connection like :-
set conJ=server.CreateObject("ADODB.Connection")
set rsJ=server.CreateObject("ADODB.Recordset")
cnJ = "Driver={MySQL ODBC 3.51 Driver};server=localhost;uid=root;database=gm"
strSQLJ="SELECT * FROM number WHERE ctype='GR'"
rsJ.open strSQLJ, cnJ

in all of my form.So when i need to change the connection then i need changing all of my form in my system.So have some easy way to solute this problem??For example using the function (include file) then the such connection will save in 1 file 1st?So do you all have some easy sample for that!So if got please reply me ok???

So thank you 1st for anyone read this message!

08-12-2005, 05:23 PM
1) Create a new file called global.asa and put the code below in it.

Sub Application_OnStart()
Application("ConnectionString") = "Driver={MySQL ODBC 3.51 Driver};server=localhost;uid=root;database=gm"
End Sub

2) When you need to open a connection, use the following code:

Dim objCon
Set objCon = Server.CreateObject("ADODB.Connection")
objCon.Open Application("ConnectionString")

08-12-2005, 05:41 PM
If you don't use the global.asa file, then put this on a page by itself, with no other code, and no html. Name it connection.asp

cnJ = "Driver={MySQL ODBC 3.51 Driver};server=localhost;uid=root;database=gm"

now to use it just add this line of code on each page that you make the connection.
<!--#include file="connection.asp" -->
This line cannot be within the asp delimiters. (<% %>)