Data source name: Difference between revisions

Content deleted Content added
WikiCleanerBot (talk | contribs)
m v2.05b - Bot T20 CW#61 - Fix errors for CW project (Reference before punctuation)
 
(17 intermediate revisions by 13 users not shown)
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}}
 
[[Internet|In]] [[computing]], a '''data source name''' ('''DSN''', sometimes known as a '''database source name''', though "[[Computer file|data sources]]" can comprise other repositories apart from [[database management system|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.<ref>[https://www.gridgain.com/docs/latest/developers-guide/SQL/ODBC/connection-string-dsn Connection String and DSN]</ref>
 
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>
 
* 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 identifier | user ID]] for data access (if required)
* a user password for data access (if required)
 
Line 18 ⟶ 19:
Two kinds of DSN exist:
 
* '''Machine DSNs''' - stored in collective configuration files (e.g., {{code|/etc/odbc.ini}}, {{code|~/.odbc.ini}}) and/or system resources (e.g., Windows Registry {{code|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., {{code|/etc/odbc.ini}}, {{code|/etc/odbc_file_dsns/<filename>}})
* '''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>}})
 
== 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:
 
<sourcesyntaxhighlight lang="vbvbscript">
Dim DatabaseObject1
Set DatabaseObject1 = Server.CreateObject("ADODB.Connection")
DatabaseObject1.Open("DSN=example;")
</syntaxhighlight>
</source>
 
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:
 
<sourcesyntaxhighlight lang="php">
require_once("DB.php");
//$dsn = "<driver>://<username>:<password>@<host>:<port>/<database>";
$dsn = "mysql://john:pass@localhost:3306/my_db";
$db = DB::connect($dsn);
</syntaxhighlight>
</source>{{Clarifyme|How is this an example of DSN use|date=June 2013}}
 
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>
PHP with PDO.
<sourcesyntaxhighlight lang="php">
$dsn = "mysql:host=localhost;dbname=example";
$dbh = new PDO($dsn, $username, $password);
</syntaxhighlight>
</source>
 
In [[Perl]], using the [[Perl_DBIPerl 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.
 
<sourcesyntaxhighlight lang="perl">
my $dsn = "DBI:Pg:database=finance;host=db.example.com;port=$port";
$dsn = "DBI:mysql:database=$database;host=$hostname;port=$port";
Line 60 ⟶ 61:
 
my $dbh = DBI->connect($dsn,'username','password');
</syntaxhighlight>
</source>
 
== See also ==
* [[Datasource]]
* [[ADO.NET]]
Line 68 ⟶ 69:
* [[ODBC]]
* [[OLE DB]]
 
== References ==
<references/>
 
{{Database}}
 
[[Category:Data access technologies| ]]
 
{{database-stub}}