What is DSN?

In this article I will explain about DSN.
  • 1337

Introduction

A data source name (DSN, sometimes known as a database source name though data sources are not limited to databases) are data structures used to describe a connection to a data source. Most commonly used in reference to ODBC, DSNs may also be defined for JDBC and other data access mechanisms.


DSN attribute

  • name of the data source
  • directory of the data source
  • name of a driver which can access the data source
  • user ID for data access (if required)
  • user password for data access (if required)

Types of DSN

Two kinds of DSN exist:

  • Machine DSNs - stored in collective configuration files (e.g., /etc/odbc.ini, ~/.odbc.ini) and/or system resources (e.g., Windows Registry HKLM\Software\ODBC\odbc.ini)
  • File DSNs - stored in the filesystem with one DSN per file

These are further broken down into

  • System DSNs - accessible by any and all processes and users of the system, stored in a centralized location (e.g., /etc/odbc.ini, /etc/odbc_file_dsns/<filename>)
  • User DSNs - accessible only by the user who created the DSN, stored in a user-specific location (e.g., ~/.odbc.ini, ~/odbc_file_dsns/<filename>)

Example of use

Dim DatabaseObject1
Set DatabaseObject1 = Server.CreateObject("ADODB.Connection")
DatabaseObject1.Open("DSN=DSNname;")

 

In PHP

require_once("DB.php");
//$dsn = "<driver>://<username>:<password>@<host>:<port>/<database>";
$dsn = "mysql://john:pass@localhost:port/my_db";
$db = DB::connect($dsn);

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answer here

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.