NCS Logo - Click for home page Northstar Developer Center
Platforms
All Platforms
.NET Framework (1.x - 4.x)
Active Server Pages
ASP.NET
C#
SQL Server
VB.NET
Visual Basic

Keywords
.NET Data Types
.NET E-mail
.NET Events
.NET Functions
.NET Object Programming
.NET System.Configuration
.NET System.Diagnostics
.NET System.IO
.NET System.Net
.NET System.Net.Sockets
Active Data Objects
ASP Architecture
ASP Black Belt
ASP Built-in Functions
ASP Built-in Objects
ASP Debugging
ASP Performance
ASP Security
ASP Syntax
ASP.NET Authentication
ASP.NET Controls
ASP.NET Data Access
ASP.NET Features
ASP.NET Master Pages
ASP.NET Page Events
ASP.NET Security
ASP.NET ViewState
Atom
Certifications
COM, DCOM, COM+
Data Access
E-Mail
Errors
Exporting Data
HTML Tips
IIS
Object-Oriented Programming
RSS
SQL
Uncategorized ASP Tips
VB API Programming
VB Forms
VB Syntax
XML

Book Support
Visual Basic 6 Bible
ASP Bible
ASP Weekend Crash Course
ASP.NET At Work
Creating Web Services

Building a DSN-Less Connection

Written by Eric Smith, Northstar Computer Systems LLC

I've gotten a few questions lately asking about DSN-less connections and how to do them in ASP. For starters, DSN stands for Data Source Name, which was a configuration setting you had to make using ODBC. Each DSN defined how to get to the database, server names, etc. When you made a connection using DAO or RDO, you could specify a DSN.

However, building DSNs are tedious and a pain, especially if you don't have easy access to the ODBC applet on the machine. ADO doesn't require the use of a DSN. Instead, you can build the connection string by hand, as shown here:

Function OpenDB()
   
   Dim dcnDB ' As ADODB.Connection
   Set dcnDB = Server.CreateObject("ADODB.Connection")
	dcnDB.ConnectionString = "Provider=Microsoft.Jet.OLEDB.3.51;" _
      & "Data Source=D:\Files\Forums.mdb;" 
   dcnDB.Open
   
   Set OpenDB = dcnDB
   
End Function
This function creates a DSN-less connection to an Access 97 database, opens it, and returns the database connection object to the caller. You can make all the DSN-less connections you need and never have to touch the server console. In addition, if you move this file to another machine, you don't have to worry about setting up the DSN on that machine. One concern you might have is in putting the user ID and password directly in your ASP file. An alternative is to store the user ID and password in another file somewhere else on your server. You open the file and read the user ID/password information and use it in the ASP file. Make sure that file is not in your web directory and make sure the web user has permission to access that file.

Keywords: [ Active Data Objects ]

Publication Date: 11/1/1999, Last Update: 2/13/2010