I hav开发者_如何转开发e a established connection to my database using
adoCon.Open "Driver={SQL Server}; Server=" & host_name & "; Database=" & db_name & "; Uid=" & user_name & "; Pwd=" & password
Now i want to use this connection on all the pages of my website. How to do that? Is there anyway to make adoCon variable public so that it can be accessible from all the pages.
Thanks
Is it Classic ASP you're talking about?
Use the global.asa file to create an application object, such as:
Sub Application_OnStart
Application("some name") = "Your connection string"
End Sub
Then you can reuse it in all your pages, such as:
Dim rsObj,cnObj, sSQL
Set cnObj = Server.CreateObject ("ADODB.Connection")
cnObj.Open Application("some name")
Set rsObj=Server.CreateObject("adodb.recordset")
sSQL="your sql string"
With rsObj
.Open sSQL, cnObj
If Not( .BOF or.EOF ) Then
[do some stuff]
End If
.Close
End With
精彩评论