Geeks With Blogs
John Conwell: aka Turbo Research in the visual exploration of data

Speaking of usefull macros, this is one I've used for a a few years and thought might be usefull.  It calls the ADODB Data Link Properties dialog (shown below).  After you go through the dialog picking your data source, database, and connection settings, it dumps out the connection string for your configuration into code window where your cursor is located.

   

Here is the code for the connection string macro:

Public Sub ConnectionStringWizard()

     Dim args() As Object

     Dim linkType As System.Type = System.Type.GetTypeFromProgID("DataLinks")

     Dim linkObj As Object = Activator.CreateInstance(linkType)

     Dim conObj = linkType.InvokeMember("PromptNew", System.Reflection.BindingFlags.InvokeMethod, Nothing, linkObj, args)

     If conObj Is Nothing = False Then

          Dim constring As String = conObj.GetType().InvokeMember("ConnectionString", System.Reflection.BindingFlags.GetProperty, Nothing, conObj, args).ToString()

          Dim textSelection As TextSelection = DTE.ActiveDocument.Selection()

          Dim edit As EditPoint = textSelection.TopPoint.CreateEditPoint()

          edit.Insert("""" & constring & """")

     End If

End Sub

Posted on Wednesday, October 26, 2005 6:50 AM Ramblings | Back to top


Comments on this post: Connection String generation Visual Studio macro

# re: Connection String generation Visual Studio macro
Requesting Gravatar...
Great idea!

Required an "Imports System" or qualifying Type and Activator as System.Type and System.Activator for me, by the way.
Left by Jon Galloway on Oct 27, 2005 1:29 PM

# re: Connection String generation Visual Studio macro
Requesting Gravatar...
great idea, indeed!

thats the beauty of implicit import statements, btw :)
Left by dominck on Oct 28, 2005 4:27 AM

# re: Connection String generation Visual Studio macro
Requesting Gravatar...
The conType variable is not needed.
You can delete this line:
Dim conType As Type = System.Type.GetTypeFromProgID("ADODB.Connection")

and you can change this line:
Dim conObj As Object = Activator.CreateInstance(conType)
to this:
Dim conObj = Nothing

conObj is being reset by the linkType.InvokeMember call.
Left by Al Gonzalez on Oct 28, 2005 4:57 AM

# re: Connection String generation Visual Studio macro
Requesting Gravatar...
Cool macro, thanx... I'll use this one a lot...
Left by Maruis Marais on Oct 30, 2005 6:59 PM

Your comment:
 (will show your gravatar)


Copyright © John Conwell | Powered by: GeeksWithBlogs.net