Изменить строку подключения в app.conig / How to change connection string in app.config

static void AddConnectionStringMyDB()
        {
            System.Configuration.Configuration config =
                ConfigurationManager.OpenExeConfiguration(
                ConfigurationUserLevel.None);
            ConnectionStringsSection csSection =
              config.ConnectionStrings;
            ConnectionStringSettings connection = new ConnectionStringSettings();
            connection.Name = "Rozn_Client.Properties.Settings.userDBConnectionString";
            connection.ProviderName = "Microsoft.SqlServerCe.Client.4.0";
            connection.ConnectionString = "Data Source=|DataDirectory|\\myDB.sdf;Password=mypassword;Persist Security Info=True";
            csSection.ConnectionStrings.Add(connection);
            config.Save(ConfigurationSaveMode.Modified);
            ConfigurationManager.RefreshSection("connectionStrings");
        }

No comments:

Post a Comment