VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Create an UDL-File from an ADO-ConnectionString

by Andreas Hofmann (1 Submission)
Category: Databases/Data Access/DAO/ADO
Compatability: Visual Basic 3.0
Difficulty: Intermediate
Date Added: Wed 3rd February 2021
Rating: (3 Votes)

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.

Inputs
ConnectionString As String, Filename As String
Assumes
Needs to have a reference to the "Microsoft Scripting Runtime".
Code Returns
None, but creates as file.
Side Effects
Overwrites the given Filename, if already exists.

Rate Create an UDL-File from an ADO-ConnectionString

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

Download this snippet    Add to My Saved Code

Create an UDL-File from an ADO-ConnectionString Comments

No comments have been posted about Create an UDL-File from an ADO-ConnectionString. Why not be the first to post a comment about Create an UDL-File from an ADO-ConnectionString.

Post your comment

Subject:
Message:
0/1000 characters