Advertisement
2_2002-2004 Databases/ Data Access/ DAO/ ADO #122383

Create an UDL-File from an ADO-ConnectionString

Creates an UDL-File (Universal Data Link) from an existing ADO-ConnectionString. Unfortunately the DataLinks-Object in the "Microsoft OLE DB Service Component 1.0 Type Library" provides some prompting dialogs to choose an ADO-Connection, but a save method to get an UDL-file is missing. So I coded this. Note that this wasn't as easy as it looks now, cause an UDL-file is no normal INI-file, although it seems to be one. The first thing is, that it must be saved in unicode. The second and very astonishing thing is, that the second line, which seems to be a missable comment, is very important and must be exactly as it is. Otherwise the UDL-file wont work! Comments and votes are welcome.

AI

Ringkasan AI: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Kode Sumber
original-source
Public Sub CreateUDLFile(ConnectionString As String, FileName As String)
 Dim FSO As New Scripting.FileSystemObject
 Dim TXT As Scripting.TextStream
 
 ' Create a File in Unicode-Mode
 Set TXT = FSO.CreateTextFile(FileName, True, True)
 With TXT
 .WriteLine "[oledb]"
 ' This line needs to be exactly as it is
 .WriteLine "; Everything after this line is an OLE DB initstring"
 .WriteLine ConnectionString
 .Close
 End With
End Sub
Komentar Asli (3)
Dipulihkan dari Wayback Machine