Connect to an MSSQL Database

 

Example:

<%

  Dim adoCon
  Dim strCon
  Dim strConDBServer
  Dim strConDBName
  Dim strConUserName
  Dim strConPassword

  strConDBServer = "server_name"
  strConDBName   = "database_name"
  strConUserName = "username"
  strConPassword = "password"

  strCon = "Provider=SQLOLEDB;Server=" & strSQLServerName & _
  ";User ID=" & strSQLDBUserName & _
  ";Password=" & strSQLDBPassword & _
  ";Database=" & strSQLDBName & ";"

  Set adoCon = Server.CreateObject("ADODB.Connection")
  adoCon.open strCon

%>

Simply change the parts in red to your own details.

Important:

It is important to remember to always close the connection to your database within your pages. But how do you close the connection to your database? Well, the example below shows you how to do just that.

<%
  adoCon.Close
%>

Once you have finished with a database remember to add the code above to your page.

Written By: S2H, 14th October 2006

Bookmark

Advertisement