Using the SSMS ConnectionDialog

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