Connection string in VBScript of ASP to connect to MSSQLASP and MSSQL is one of the popular combinations to develop web based applications. Here by using VBScript ADO ( ActiveX Data Object) we will establish the connection from our ASP script to MSSQL database. Here the connection string part we will discuss. You care read more details on the ADO objects here.
We will create our connection string and keep in a separate asp file. This asp file ( let us name it conn.asp ) we will place in our server root directory and call it ( or include ) from different pages of our application like this.
<!-- #include virtual = "/conn.asp" -->So all the files having any type of transaction with the database, can just use the connection string by calling the file like this. This way at a common place the login information of the MSSQL database is stored this way it is easy to maintain. Imagine an application having 100 asp pages where every page has database connection string at the top. If we shift the hosting account to a new server then we have to update the login information of the new database in all the 100 pages. So it is better to keep the connection string at a common place for better maintainability.
Here is the code inside our conn.asp page.
We have to replace source_name, db_name, userid and password with our details.