What is System DSN? how to use it in ASP for connecting to DATABASE

Posted Jun 15, 2009 by rajeshchoudhary / comments 0 comments / Print / Font Size Decrease font size Increase font size

This article tells all about Data Source Name(DSN) DSN types uses.this also describes how to create a DSN to SQL server Database and make a connection to Database using this DSN in ASP.

DSN stands for Data Source Name.DSN is used for making a connection to a number of databases(Sql,mysql,Access,excel,Dbase,foxpro what not) using ODBC Driver

There are various types of DSN

These DSN differs in terms of
Where DSN info is being stored?
Who can Access that Particular DSN?

File DSN Access-   Any user who has access to the File System.  Storing Way-DSN information is stored In a text file with .DSN extension.
System DSN Access-   Any user on that system.         Storing Way- DSN information is stored in Local Machine Section of System Registry.
User DSN        Access-   Only for the user who created that Data Source. if that machine has more than one user you are logged in deifferent user than you cant see User DSN from this new account. Storing Way- DSN information is stored in current section of System Registry.
UDL (Universal Data Link) Access-   Any user who has access to the File System. Storing Way-DSN information is stored In a  file with .UDL extension.
DSN-less   Access-   Any one who has access to the database files (i.e. mdb,.xls) if it is Sql aerver then you must know username and password. Storing Way-connection information is not stored in file or registry you have to make a connection to your database from your code using connection string

Here we are trying to explain it by making a connection from our ASP program to a SQL Server using System DSN.

DSN should be created on the server where your Sqlserver Database is residing.


Steps to create a DSN for SQL server
1. GOTO 'Control Panel'.
2. Then GOTO 'Administration Tools'.
3. Then GOTO 'Data Sources ODBC'.
4. GOTO System DSN tab.
5. Click on Add.
6. 'Create A new Data Source' dialog Box appear Select a driver in this case SQl server and click finish.
7. 'Create a new data source to SQL' dialog box will appear.Give Name of DSN and select SQL server from list Click next.
8. in next screen you can provide which authintication you are going to use ie windows based or SQL Serevr based.
9. By using Sql server authorization all database will be listed in next screen if that user is authorised to do that.

Once your DSN is created you can access that Database through this DSN  from our ASP Code.
in connection String we provided DSN name mydsn , username and  password
 Dim conn,rs
 Set conn=Server.CreateObject("ADODB.Connection")
 Set rs=Server.CreateObject("ADODB.RecordSet")
 connect_string="DSN=mydsn;uid=abc;pwd=abc;"
 conn.Open connect_string
 dim query
 query ="select emp_num,emp_name,dob where emp_status='A'"
 set rs=conn.execute(query)

Happy Coding.

Rate this Article:

Be the first to rate me.

  • Nothing Found!

    Why not submit your own content? Signup here.


* You must be logged in order to leave comments, please login or join us.

Comments

No comments yet.



Bookmark and Share
Sign up for our email newsletter
Name:
Email: