In my application, that connecting to MS Sql database, I am using Microsoft.Data.ConnectionUI
And my application work in my computer. If i run this application in another computer, when i open connection dialog, i see that error:
That is my code for this:
try
{
connectionString = ShowDialogConnection();
SqlConnection connect = new SqlConnection(connectionString);
connect.Open();
backgroundWorker1.RunWorkerAsync();
}
catch (Exception exc)
{
MessageBox.Show(exc.ToString());
}
string ShowDialogConnection()
{
string conn = "";
DataConnectionDialog dlg = new DataConnectionDialog();
DataSource.AddStandardDataSources(dlg);
dlg.SelectedDataSource = DataSource.SqlDataSource;
dlg.SelectedDataProvider = DataProvider.SqlDataProvider;
if (ConfigurationManager.ConnectionStrings["ConStr"] != null)
{
dlg.ConnectionString = ConfigurationManager.ConnectionStrings["ConStr"].ConnectionString;
}
if (DataConnectionDialog.Show(dlg) == DialogResult.OK)
{
if (dlg.ConnectionString != null && dlg.ConnectionString != "")
{
conn = dlg.ConnectionString;
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
ConnectionStringsSection csSection = config.ConnectionStrings;
csSection.SectionInformation.ProtectSection("RsaProtectedConfigurationProvider");
csSection.SectionInformation.ForceSave = true;
ConnectionStringSettings csSettings = new ConnectionStringSettings("ConStr", dlg.ConnectionString, "System.Data.SqlClient");
if (csSection.ConnectionStrings["ConStr"] != null)
csSection.ConnectionStrings.Remove("ConStr");
csSection.ConnectionStrings.Add(csSettings);
config.Save(ConfigurationSaveMode.Modified);
}
}
return conn;
}
What I need to do with this?