Click Here To Get Amazing Facebook Profile Covers,Status Messages

Data Source Name(DSN) Connection to database in ASP using DSN

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.

Your rating: None Average: 4.5 (2 votes)