在我的应用程序中,连接到MS sql数据库,我使用的是Microsoft.Data.ConnectionUI
我的应用程序在我的计算机上工作.如果我在另一台计算机上运行此应用程序,当我打开连接对话框时,我看到该错误:
我的应用程序在我的计算机上工作.如果我在另一台计算机上运行此应用程序,当我打开连接对话框时,我看到该错误:
这是我的代码:
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; }
我需要做什么呢?