Visual Basic Concepts

Creating DSN-less RDO Connections

Another approach to consider when establishing RDO connections is to provide all required information in the Connect argument of the OpenConnection method. This approach affords a number of advantages:

If you choose to use a DSN-less connection, you must include the name of the server and driver along with any other user-specific information in the connect string. However, if you choose this option, you can only use the default OEMTOANSI (Off), NETWORK (named pipes), and other settings that can only be set when creating a DSN.

If you choose to create a DSN-less connection, you must pass a zero-length string as the dsName argument of the OpenConnection method, or the Database property of the RemoteData control. This notifies the ODBC driver that you want to create a DSN-less connection. In addition, note that the order of the connect string arguments is significant. The DSN argument must be provided after the SERVER and DRIVER arguments, as shown below.

The following example illustrates creation of a DSN-less connection to establish a connection to a Microsoft SQL Server database named MyServer:

Dim Cn As rdoConnection
Dim En as rdoEnvironment, Conn As String
Set En = rdoEnvironments(0)
Conn$ = "UID=Holly;PWD=Huskador;" _ 
   & "DATABASE=MyDb;" _ 
   & "SERVER=MyServer;" _ 
   & "DRIVER={SQL SERVER};DSN='';"
Set Cn = En.OpenConnection(dsName:="", _ 
   prompt:=rdDriverNoPrompt, _ 
   connect:=Conn$)