Database Source Name
Encyclopedia
In computing
Computing
Computing is usually defined as the activity of using and improving computer hardware and software. It is the computer-specific part of information technology...

, a data source name (DSN, sometimes known as a database source name though data sources are not limited to databases
Database management system
A database management system is a software package with computer programs that control the creation, maintenance, and use of a database. It allows organizations to conveniently develop databases for various applications by database administrators and other specialists. A database is an integrated...

) are data structure
Data structure
In computer science, a data structure is a particular way of storing and organizing data in a computer so that it can be used efficiently.Different kinds of data structures are suited to different kinds of applications, and some are highly specialized to specific tasks...

s 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 attributes may include, but are not limited to:
  • 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)


The system administrator of a client machine creates a separate DSN for each relevant data source.

Standardizing DSNs offers a level of indirection
Indirection
In computer programming, indirection is the ability to reference something using a name, reference, or container instead of the value itself. The most common form of indirection is the act of manipulating a value through its memory address. For example, accessing a variable through the use of a...

 that various applications (for example: Apache
Apache HTTP Server
The Apache HTTP Server, commonly referred to as Apache , is web server software notable for playing a key role in the initial growth of the World Wide Web. In 2009 it became the first web server software to surpass the 100 million website milestone...

/PHP
PHP
PHP is a general-purpose server-side scripting language originally designed for web development to produce dynamic web pages. For this purpose, PHP code is embedded into the HTML source document and interpreted by a web server with a PHP processor module, which generates the web page document...

 and IIS
Internet Information Services
Internet Information Services – formerly called Internet Information Server – is a web server application and set of feature extension modules created by Microsoft for use with Microsoft Windows. It is the most used web server after Apache HTTP Server. IIS 7.5 supports HTTP, HTTPS,...

/ASP
Active Server Pages
Active Server Pages , also known as Classic ASP or ASP Classic, was Microsoft's first server-side script engine for dynamically-generated Web pages. Initially released as an add-on to Internet Information Services via the Windows NT 4.0 Option Pack Active Server Pages (ASP), also known as Classic...

) can take advantage of in accessing shared data sources.

Types of data source name

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/)
  • User DSNs - accessible only by the user who created the DSN, stored in a user-specific location (e.g., ~/.odbc.ini, ~/odbc_file_dsns/)

Misuse of the term

The term DSN is sometimes mistakenly used in place of connection string
Connection string
In computing, a connection string is a string that specifies information about a data source and the means of connecting to it. It is passed in code to an underlying driver or provider in order to initiate the connection...

. A connection string typically fully describes a data source, while a DSN typically relies on some external system resources and/or configuration files.

Example of use

Software (e.g., Crystal Reports, Microsoft Excel, PHP, Perl, Python, Ruby) users can submit CRUD (Create, Read, Update, Delete) queries to a data source by establishing a connection to the DSN.

ASP (VBScript
VBScript
VBScript is an Active Scripting language developed by Microsoft that is modeled on Visual Basic. It is designed as a “lightweight” language with a fast interpreter for use in a wide variety of Microsoft environments...

) code to open a DSN connection might look like the following:


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


In PHP
PHP
PHP is a general-purpose server-side scripting language originally designed for web development to produce dynamic web pages. For this purpose, PHP code is embedded into the HTML source document and interpreted by a web server with a PHP processor module, which generates the web page document...

using the PEAR::DB package to open a connection without an external DSN (a "DSN-less connection", i.e., using a Connection String), the code might resemble the following:


require_once("DB.php");
//$dsn = "://:@:/";
$dsn = "mysql://john:pass@localhost:port/my_db";
$db = DB::connect($dsn);
The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK