Revision as of 11:13, 28 January 2015 editPacerier (talk | contribs)1,866 edits →Misuse of the term← Previous edit | Latest revision as of 01:28, 22 June 2023 edit undoCedar101 (talk | contribs)Extended confirmed users16,544 edits →Example of use: fix syntaxhighlight error | ||
(25 intermediate revisions by 21 users not shown) | |||
Line 1: | Line 1: | ||
{{Short description|String that has an associated data structure used to describe a connection to a data source}} | |||
{{Unreferenced|date=January 2009}} | |||
{{More citations needed|date=April 2022}} | |||
In ], a '''data source name''' ('''DSN''', sometimes known as a '''database source name''', though "] |
] ], a '''data source name''' ('''DSN''', sometimes known as a '''database source name''', though "]" can comprise other repositories apart from ]) is a string that has an associated ] used to describe a connection to a data source. Most commonly used in connection with ], DSNs also exist for ] and for other data access mechanisms. The term often overlaps with "]". Most systems do not make a distinction between DSNs or connection strings and the term can often be used interchangeably.<ref></ref> | ||
DSN attributes may include, but are not limited to: | DSN attributes may include, but are not limited to:<ref></ref> | ||
* the name of the data source | * the name of the data source | ||
* the location of the data source | * the location of the data source | ||
* the name of a ] which can access the data source | * the name of a ] which can access the data source | ||
* a ] for data access (if required) | * a ] for data access (if required) | ||
* a user password for data access (if required) | * a user password for data access (if required) | ||
Line 18: | Line 19: | ||
Two kinds of DSN exist: | Two kinds of DSN exist: | ||
* '''Machine DSNs''' |
* '''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''' |
* '''File DSNs''' – stored in the filesystem with one DSN per file | ||
These are further broken down into |
These are further broken down into | ||
* '''System DSNs''' |
* '''System DSNs''' – accessible by any and all processes and users of the system, stored in a centralized location (e.g., {{code|/etc/odbc.ini}}, {{code|//etc/odbc_file_dsns/<filename>}}) | ||
* '''User DSNs''' |
* '''User DSNs''' – accessible only by the user who created the DSN, stored in a user-specific location (e.g., {{code|/~/.odbc.ini}}, {{code|/~/odbc_file_dsns/<filename>}}) | ||
==Misuse of the term== | |||
The term DSN is sometimes mistakenly used in place of ]. A connection string {{citation needed span|text=typically fully describes a data source}}, while a DSN {{citation needed span|text=typically relies on some external system resources and/or configuration file}}. | |||
== Example of use == | == 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. |
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. | ||
might look like the following: | ASP (]) code to open a DSN connection might look like the following: | ||
< |
<syntaxhighlight lang="vbscript"> | ||
Dim DatabaseObject1 | Dim DatabaseObject1 | ||
Set DatabaseObject1 = Server.CreateObject("ADODB.Connection") | Set DatabaseObject1 = Server.CreateObject("ADODB.Connection") | ||
DatabaseObject1.Open("DSN= |
DatabaseObject1.Open("DSN=example;") | ||
</syntaxhighlight> | |||
</source> | |||
In ] 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 | In ] 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 | ||
< |
<syntaxhighlight lang="php"> | ||
require_once("DB.php"); | require_once("DB.php"); | ||
//$dsn = "<driver>://<username>:<password>@<host>:<port>/<database>"; | //$dsn = "<driver>://<username>:<password>@<host>:<port>/<database>"; | ||
$dsn = "mysql://john:pass@localhost:3306/my_db"; | $dsn = "mysql://john:pass@localhost:3306/my_db"; | ||
$db = DB::connect($dsn); | $db = DB::connect($dsn); | ||
</ |
</syntaxhighlight>{{Clarify|How is this an example of DSN use|date=June 2013}} | ||
PHP with PDO. | |||
⚫ | ==See also== | ||
<syntaxhighlight lang="php"> | |||
$dsn = "mysql:host=localhost;dbname=example"; | |||
$dbh = new PDO($dsn, $username, $password); | |||
</syntaxhighlight> | |||
In ], using the ] module, each driver has its own syntax for the DSN attributes. The only requirement that DBI makes is that all the information, except for username and password is supplied in a single string argument. | |||
<syntaxhighlight lang="perl"> | |||
my $dsn = "DBI:Pg:database=finance;host=db.example.com;port=$port"; | |||
$dsn = "DBI:mysql:database=$database;host=$hostname;port=$port"; | |||
$dsn = "DBI:Oracle:host=$host;sid=$sid;port=$port"; | |||
$dsn = "DBI:SQLite:dbname=$dbfilename"; | |||
my $dbh = DBI->connect($dsn,'username','password'); | |||
</syntaxhighlight> | |||
⚫ | == See also == | ||
* ] | |||
* ] | * ] | ||
* ] | * ] | ||
* ] | * ] | ||
* ] | * ] | ||
== References == | |||
<references/> | |||
{{Database}} | {{Database}} | ||
] | ] | ||
{{database-stub}} |
Latest revision as of 01:28, 22 June 2023
String that has an associated data structure used to describe a connection to a data sourceThis article needs additional citations for verification. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed. Find sources: "Data source name" – news · newspapers · books · scholar · JSTOR (April 2022) (Learn how and when to remove this message) |
In computing, a data source name (DSN, sometimes known as a database source name, though "data sources" can comprise other repositories apart from databases) is a string that has an associated data structure used to describe a connection to a data source. Most commonly used in connection with ODBC, DSNs also exist for JDBC and for other data access mechanisms. The term often overlaps with "connection string". Most systems do not make a distinction between DSNs or connection strings and the term can often be used interchangeably.
DSN attributes may include, but are not limited to:
- the name of the data source
- the location of the data source
- the name of a database driver which can access the data source
- a user ID for data access (if required)
- a user password for data access (if required)
The system administrator of a client machine generally creates a separate DSN for each relevant data source.
Standardizing DSNs offers a level of indirection; various applications (for example: Apache/PHP and IIS/ASP) can take advantage of this 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/<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
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) code to open a DSN connection might look like the following:
Dim DatabaseObject1 Set DatabaseObject1 = Server.CreateObject("ADODB.Connection") DatabaseObject1.Open("DSN=example;")
In PHP 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 = "<driver>://<username>:<password>@<host>:<port>/<database>"; $dsn = "mysql://john:pass@localhost:3306/my_db"; $db = DB::connect($dsn);
PHP with PDO.
$dsn = "mysql:host=localhost;dbname=example"; $dbh = new PDO($dsn, $username, $password);
In Perl, using the Perl DBI module, each driver has its own syntax for the DSN attributes. The only requirement that DBI makes is that all the information, except for username and password is supplied in a single string argument.
my $dsn = "DBI:Pg:database=finance;host=db.example.com;port=$port"; $dsn = "DBI:mysql:database=$database;host=$hostname;port=$port"; $dsn = "DBI:Oracle:host=$host;sid=$sid;port=$port"; $dsn = "DBI:SQLite:dbname=$dbfilename"; my $dbh = DBI->connect($dsn,'username','password');
See also
References
Database | |
---|---|
Main | |
Languages | |
Security | |
Design |
|
Programming | |
Management | |
Lists of | |
See also | |
WikiProject Category |