Content deleted Content added
m Dating maintenance tags: {{Clarifyme}} |
m v2.05b - Bot T20 CW#61 - Fix errors for CW project (Reference before punctuation) |
||
(42 intermediate revisions by 30 users not shown) | |||
Line 1:
{{Short description|String that has an associated data structure used to describe a connection to a data source}}
{{More citations needed|date=April 2022}}
[[Internet|In]] [[computing]], a '''data source name''' ('''DSN''', sometimes known as a '''database source name''', though "[[Computer file|data sources]]"
DSN attributes may include, but are not limited to:<ref>[https://docs.microsoft.com/en-us/sql/connect/odbc/dsn-connection-string-attribute?view=sql-server-ver15 ODBC DSN connection strings]</ref>
* name of the data source▼
* ___location 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 name of the data source
The system administrator of a client machine creates a separate DSN for each relevant data source.▼
▲* the ___location of the data source
▲* the name of a [[database driver]] which can access the data source
▲The system administrator of a client machine generally creates a separate DSN for each relevant data source.
Standardizing DSNs offers a level of [[indirection]] that various applications (for example: [[Apache HTTP Server|Apache]]/[[PHP]] and [[Internet Information Services|IIS]]/[[Active Server Pages|ASP]]) can take advantage of in accessing shared data sources.▼
▲Standardizing DSNs offers a level of [[indirection]]
== Types of data source name ==
Two kinds of DSN exist:
* '''Machine DSNs'''
* '''File DSNs'''
These are further broken down into
* '''System DSNs'''
* '''User DSNs'''
== 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=
</syntaxhighlight>
In [[PHP]] using the [https://pear.php.net/package/DB/ PEAR::DB] package to open a connection without an external DSN (a "DSN-less connection", i.e., using a Connection String){{Clarify|How is this an example of DSN use|date=June 2013}}, 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);
</syntaxhighlight>
PHP with PDO:<ref>{{cite web |title=PHP: PDO - Manual |url=https://www.php.net/pdo |website=www.php.net |access-date=22 January 2025 |language=en}}</ref>
==See also==▼
<syntaxhighlight lang="php">
$dsn = "mysql:host=localhost;dbname=example";
$dbh = new PDO($dsn, $username, $password);
</syntaxhighlight>
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.
<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 ==
* [[Datasource]]
* [[ADO.NET]]
* [[JDBC]]
* [[ODBC]]
* [[OLE DB]]
== References ==
<references/>
{{Database}}
[[Category:Data access technologies| ]]
|