在我的應用程序,連接到MS Sql數據庫,我使用Microsoft.Data.ConnectionUI
而我的應用程序在我的電腦工作。如果我在運行另一臺計算機此應用中,當我打開連接對話框,我看到這個錯誤: 無法解密使用提供商'RsaProtectedConfigurationProvider'
這是我此代碼:
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;
}
我需要這個做什麼?
您能否爲我們提供來自提供商的錯誤消息? – 2013-04-24 09:02:37
@RemusRusanu是的,我可以。 「來自提供者的錯誤消息:錯誤的數據。」 – EXTRAM 2013-04-24 12:27:54