Connection String Romance Continued


Continuing from the latest blog post, I finally made some breakthrough in my knowledge. It is true that the best teacher is your own experience.

The main problem in  the connection string between me and ASP classic is the connection string suddenly changed when I navigate through pages in ASP.

Dim madoConx
Set madoConx = Nothing
Set madoConx = Server.CreateObject("ADODB.Connection")
madoConx.ConnectionString = conStr
madoConx.Open conStr
Set Session("connection") = madoConx

Instead on believing that the connection is already correct, one should double check again because the ADODB connection does not using the same connection string you have defined.

In other page, the connection string strips some values and then left only the connection which is safe, but unusable. Why unusable? There are values like username and passwords stripped from the connection string. This made me sure that the connection is either best placed in a separate method that can be called from any page (of course with some security to prevent anonymous call) or the ADODB connection is only suited for access database.

IF SOMEHOW YOU PERSIST ON PUTTING THE CONNECTION IN GLOBAL.ASA

Below code can help.

Dim madoConx
Set madoConx = Nothing
Set madoConx = Server.CreateObject("ADODB.Connection")
madoConx.ConnectionString = conStr
madoConx.Open conStr
madoConx.Close ' this one will close the connection
madoConx.ConnectionString = conStr ' reset the connection string
Set Session("connectionString") = madoConx
Advertisements

Author: Aditya Yedija Situmeang

Developer, Lover, Christian, Omnomnomnivore, Gamer.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s