[link] Connection String generation Visual Studio macro
Cool connection string generator macro from John
Conwell :
Speaking of useful 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.
Public
Sub ConnectionStringWizard() < /SPAN > Dim args() As ObjectDim linkType As System.Type = System.Type.GetTypeFromProgID("DataLinks")
Dim linkObj As Object = System.Activator.CreateInstance(linkType)
Dim conType As System.Type = System.Type.GetTypeFromProgID("ADODB.Connection")
Dim conObj As Object = System.Activator.CreateInstance(conType)
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
Source: John Conwell - Connection String generation Visual Studio macro