Using the SSMS ConnectionDialog

Published Jan 15 2019 04:44 PM 196 Views
Microsoft
First published on MSDN on Aug 12, 2015

I was attempting to add the SSMS connection dialog to my utility and ran into problems with referenced assemblies.

The ConnectionDialog is documented here: https://msdn.microsoft.com/en-us/library/microsoft.sqlserver.management.ui.connectiondlg.aspx ...

The following is a snippet using the SSMS ConnectionDialog in a C# application.

Microsoft.SqlServer.Management.UI.ConnectionDlg.

ConnectionDialog dlg = new Microsoft.SqlServer.Management.UI.ConnectionDlg.ConnectionDialog();

Microsoft.SqlServer.Management.Smo.RegSvrEnum.

UIConnectionInfo connInfo = new Microsoft.SqlServer.Management.Smo.RegSvrEnum.UIConnectionInfo { ApplicationName = "My App" };

IDbConnection conn;
dlg.AddServer(new Microsoft.SqlServer.Management.UI.ConnectionDlg.SqlServerType());
dlg.Text = "Connect to My Database";

DialogResult dr = dlg.ShowDialogValidateConnection(this, ref connInfo, out conn);
if (DialogResult.OK == dr)
{
m_strConnString = conn.ConnectionString + ";Pooling=TRUE";
if(false == m_strConnString.Contains("Database="))
m_strConnString += ";Database=MyDb";

bRC = true;
}
else
{
bRC = false;
}

To compile the properly, references to the RegSvrEnum and ManagementControls are required.   I compiled it on my system and provided it to a peer, who quickly caused the application to fail with missing assembly references.

I built the application using the SQL Server SSMS 2015 July Preview and they had SQL Server 2014 on their system.   No problem I made sure both assemblies were in the same directory as my application but this still failed.

Following the trail of missing assemblies I had to provide the following in order for the application to execute.

  • Microsoft.SqlServer.Management.Controls
  • Microsoft.SqlServer.Management.UserSettings
  • Microsoft.SqlServer.RegSvrEnum
  • SqlWorkbbench.Interfaces

There is not a redistributable package containing these assemblies.  The supported way is to install the matching SSMS package on the target system.   SSMS can be installed separately using the following link: https://msdn.microsoft.com/en-us/library/mt238290.aspx?f=255&MSPPError=-2147217396

Bob Dorr - Principal SQL Server Escalation Engineer


%3CLINGO-SUB%20id%3D%22lingo-sub-318637%22%20slang%3D%22en-US%22%3EUsing%20the%20SSMS%20ConnectionDialog%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-318637%22%20slang%3D%22en-US%22%3E%0A%20%26lt%3Bmeta%20http-equiv%3D%22Content-Type%22%20content%3D%22text%2Fhtml%3B%20charset%3DUTF-8%22%20%2F%26gt%3B%3CSTRONG%3E%20First%20published%20on%20MSDN%20on%20Aug%2012%2C%202015%20%3C%2FSTRONG%3E%20%3CBR%20%2F%3E%3CP%3EI%20was%20attempting%20to%20add%20the%20SSMS%20connection%20dialog%20to%20my%20utility%20and%20ran%20into%20problems%20with%20referenced%20assemblies.%3C%2FP%3E%0A%20%20%3CP%3EThe%20ConnectionDialog%20is%20documented%20here%3A%20%3CB%3E%20%3CA%20href%3D%22https%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Fmicrosoft.sqlserver.management.ui.connectiondlg.aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3E%20https%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Fmicrosoft.sqlserver.management.ui.connectiondlg.aspx%20%3C%2FA%3E%20%3C%2FB%3E%3C%2FP%3E%0A%20%20%3CP%3EThe%20following%20is%20a%20snippet%20using%20the%20SSMS%20%3CEM%3E%20ConnectionDialog%20%3C%2FEM%3E%20in%20a%20C%23%20application.%3C%2FP%3E%0A%20%20%3CBLOCKQUOTE%3E%0A%20%20%20%3CP%3EMicrosoft.SqlServer.Management.UI.ConnectionDlg.%3C%2FP%3E%0A%20%20%3C%2FBLOCKQUOTE%3EConnectionDialog%20dlg%20%3D%20new%20Microsoft.SqlServer.Management.UI.ConnectionDlg.ConnectionDialog()%3B%3CP%3EMicrosoft.SqlServer.Management.Smo.RegSvrEnum.%3C%2FP%3EUIConnectionInfo%20connInfo%20%3D%20new%20Microsoft.SqlServer.Management.Smo.RegSvrEnum.UIConnectionInfo%20%7B%20ApplicationName%20%3D%20%22My%20App%22%20%7D%3B%3CP%3EIDbConnection%20conn%3B%20%3CBR%20%2F%3E%20dlg.AddServer(new%20Microsoft.SqlServer.Management.UI.ConnectionDlg.SqlServerType())%3B%20%3CBR%20%2F%3E%20dlg.Text%20%3D%20%22Connect%20to%20My%20Database%22%3B%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3EDialogResult%20dr%20%3D%20dlg.ShowDialogValidateConnection(this%2C%20ref%20connInfo%2C%20out%20conn)%3B%20%3CBR%20%2F%3E%20if%20(DialogResult.OK%20%3D%3D%20dr)%20%3CBR%20%2F%3E%20%7B%20%3CBR%20%2F%3E%20m_strConnString%20%3D%20conn.ConnectionString%20%2B%20%22%3BPooling%3DTRUE%22%3B%20%3CBR%20%2F%3E%20if(false%20%3D%3D%20m_strConnString.Contains(%22Database%3D%22))%20%3CBR%20%2F%3E%20m_strConnString%20%2B%3D%20%22%3BDatabase%3DMyDb%22%3B%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20bRC%20%3D%20true%3B%20%3CBR%20%2F%3E%20%7D%20%3CBR%20%2F%3E%20else%20%3CBR%20%2F%3E%20%7B%20%3CBR%20%2F%3E%20bRC%20%3D%20false%3B%20%3CBR%20%2F%3E%20%7D%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3ETo%20compile%20the%20properly%2C%20references%20to%20the%20RegSvrEnum%20and%20ManagementControls%20are%20required.%26nbsp%3B%26nbsp%3B%20I%20compiled%20it%20on%20my%20system%20and%20provided%20it%20to%20a%20peer%2C%20who%20quickly%20caused%20the%20application%20to%20fail%20with%20missing%20assembly%20references.%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3EI%20built%20the%20application%20using%20the%20SQL%20Server%20SSMS%202015%20July%20Preview%20and%20they%20had%20SQL%20Server%202014%20on%20their%20system.%26nbsp%3B%26nbsp%3B%20No%20problem%20I%20made%20sure%20both%20assemblies%20were%20in%20the%20same%20directory%20as%20my%20application%20but%20this%20still%20failed.%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3EFollowing%20the%20trail%20of%20missing%20assemblies%20I%20had%20to%20provide%20the%20following%20in%20order%20for%20the%20application%20to%20execute.%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CUL%3E%0A%20%20%20%3CLI%3EMicrosoft.SqlServer.Management.Controls%3C%2FLI%3E%0A%20%20%20%3CLI%3EMicrosoft.SqlServer.Management.UserSettings%3C%2FLI%3E%0A%20%20%20%3CLI%3EMicrosoft.SqlServer.RegSvrEnum%3C%2FLI%3E%0A%20%20%20%3CLI%3ESqlWorkbbench.Interfaces%3C%2FLI%3E%0A%20%20%3C%2FUL%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3EThere%20is%20not%20a%20redistributable%20package%20containing%20these%20assemblies.%26nbsp%3B%20The%20supported%20way%20is%20to%20install%20the%20matching%20SSMS%20package%20on%20the%20target%20system.%26nbsp%3B%26nbsp%3B%20SSMS%20can%20be%20installed%20separately%20using%20the%20following%20link%3A%20%3CA%20href%3D%22https%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Fmt238290.aspx%3Ff%3D255%26amp%3BMSPPError%3D-2147217396%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3E%20https%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Fmt238290.aspx%3Ff%3D255%26amp%3BMSPPError%3D-2147217396%20%3C%2FA%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%0A%20%20%3CP%3EBob%20Dorr%20-%20%3CA%20href%3D%22mailto%3Ardorr%40Principal%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3E%20Principal%20SQL%20Server%20Escalation%20Engineer%20%3C%2FA%3E%3C%2FP%3E%0A%20%20%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-318637%22%20slang%3D%22en-US%22%3EFirst%20published%20on%20MSDN%20on%20Aug%2012%2C%202015%20I%20was%20attempting%20to%20add%20the%20SSMS%20connection%20dialog%20to%20my%20utility%20and%20ran%20into%20problems%20with%20referenced%20assemblies.%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-318637%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3Essms%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Version history
Last update:
‎Jan 15 2019 04:44 PM
Updated by: