Data Links provide a convenient way to create and verify a connection string that can be used to connect to an OLE DB data source. The connection string information is persisted in a specific format in a Data Link file with the .udl extension. The functionality is similar to the Open Database Connectivity (ODBC) file Data Source Names (DSNs), but .udl files contain Unicode characters.
The following is the content of a sample Data Link file. You can edit this file using a Unicode text editor such as Microsoft Notepad.
[oledb]
; Everything after this line is an OLE DB initstring.
Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=pubs;Data Source=myServer
The following code shows how to prompt the user to get the connection information in Visual Basic 6.0 using Data Links. To use this code, set project references to the Microsoft ActiveX Data Objects 2.x Library and the Microsoft OLE DB Service Component 1.0 Type Library. When you use Visual C++ 6.0, the
CDataSource Active Template Library (ATL) class provides similar functionality.
Dim cnn As ADODB.Connection
Dim dlk As MSDASC.DataLinks
Set cnn = New ADODB.Connection
Set dlk = New MSDASC.DataLinks
cnn.ConnectionString = dlk.PromptNew
cnn.Open
There are two ways to persist Data Link files programmatically: