
A symbolic name that represents a specific connection to a database. It stores the critical address and credentials needed for an application to locate and communicate with a data provider.
Think of a DSN like a speed-dial entry on your phone. Instead of typing in the full IP address, port number, protocol, and database name every time you want to connect, you just tell your application to use Marketing_DB.
How a DSN Works
When an application (like Excel or a web server) wants to access data via ODBC, it looks for a DSN. The DSN acts as a pointer that tells the ODBC Driver Manager:
- Which Driver to use (e.g., MySQL, SQL Server, Oracle).
- Where the Database is (IP address or Server Name).
- Which Database to open on that server.
- How to Authenticate (Username and Password, though these are sometimes omitted for security).
The Three Types of DSNs
Depending on who needs to access the data, DSNs are categorized into three types:
- User DSN
- Scope: Specific to the user who created it.
- Visibility: Only visible and usable when that specific user is logged into the computer.
- Best for: Personal data analysis or local reporting tools.
- System DSN
- Scope: Global to the entire computer.
- Visibility: Any user logged into the machine can use it. Even “System Services” (like a web server running in the background) can access it.
- Best for: Web servers, automated tasks, and shared workstations.
- File DSN
- Scope: Stored in a physical file (usually with a
.dsnextension). - Visibility: Can be shared between different computers by copying the file.
- Best for: Development teams who need to share connection settings without manually configuring every machine.
- Scope: Stored in a physical file (usually with a
DSN vs. DSN-less Connections
In modern development, you might encounter DSN-less connections.
| Feature | DSN Connection | DSN-less Connection |
| Setup | Must be configured in the OS (ODBC Administrator). | Hardcoded in the application’s “Connection String.” |
| Maintenance | Easy to change the server IP in one place. | Requires code changes to update the server IP. |
| Portability | Harder to move (must recreate DSN on new PC). | Very portable (it’s just a string of text in the code). |
Example of a DSN Configuration
If you were to peek under the hood of a typical DSN, it would contain key-value pairs like this:
DSN Name: Sales_Remote
Driver: SQL Server Native Client 11.0
Server: 192.168.1.50
Database: Sales_2024
Trusted_Connection: Yes Managing DSNs
On Windows, DSNs are managed through the ODBC Data Source Administrator. You can find this by searching for ODBC in the Start Menu. Note: There are separate versions for 32-bit and 64-bit drivers!