Friday 23 November 2012

How to create a System DSN for Microsoft SQL Server


This article will help you to create a System Data Source Name (DSN) for Microsoft SQL Server on your local machine. 

Open Control Panel window, you will see different icons as shown in Pic 1.
Double click on ODBC Data Source Administrator icon.  




Pic 1.
Now you will see ODBC Data Source Administrator window (as shown below).
Select System DSN tab, and click Add.


Pic 2.
To Create a new DSN for an Microsoft SQL Server, Select SQL Server driver and click Finish.


Pic 3.
In this example I am using DSN name as MyDSN.
Enter the name you like to use for DSN and then choose SQL Server to which you want to connect. If SQL Server is located on the same machine you can choose Local. If Server is not located on the same machine then you need to enter the IP Address or domain name to connect to that Server.
Enter the domain name or IP Address and Click Next.


Pic 4.
Choose authenication method. Enter your Login ID and Password to connect to SQL Server and Click Next two time to skip next Screen, then Click Finish.


Pic 5.

At last step you will have the option to test your Connection.
After a System DSN has been created you can use it within any ASP page located on the same computer.

Connecting to database with DSN Connection

To store the information of a Data Connection for an Access or SQL database you can create a System Data Sourse Name (Syatem DSN). If you have not created a System DSN check these Articles.

After a System DSN is created you can open connection to that database in an ASP page with this simple code.

   <%
    Set MyConn = Server.CreateObject("ADODB.Connection")
    MyConn.Open "DSN=MyDSN;UID=Admin;PWD=Test"
   %>

Access database

If you are connecting to an Access database then replace Admin and test with the UserName and Password of that Access database.
Microsoft SQL Server If you are Connecting to Microsoft SQL Server then replace Admin and test with valid SQL Server Login Name and Password.
If you are connecting to an Access database and your Access database don't need UserID and Password to connect then your code.




No comments:

Post a Comment