Creating a DSN 'On the Fly'

So far, each of our connections has assumed that we have previously defined a Data Source Name (DSN). The DSN describes a data source, and the standard settings to be used when attaching to it. However, this can be limiting in some circumstances—especially when attaching to data sources that are dynamic in nature.

For example, let’s take a situation where the user connects to several servers, depending on the information they need. We could setup an ODBC Data Source Name definition for each server and selectively attach to it. A better way is to create the connection 'on the fly', without using a DSN:

ServerName = Request.QueryString("ServerName")   'from the submitted page
DBConn.Open "Driver={SQL Server};Server=" & ServerName & _    
    ";UID=sa;PWD=;WSID=MAINFRAME;Language=us_english;Database=Forum;DSN=;"
...

In this example we create a definition on the fly, using the server name from a form submitted by the user to determine which SQL Server to attach to.

© 1997 by Wrox Press. All rights reserved.