How to vary connection string for different work locations

后端 未结 7 2044
情话喂你
情话喂你 2021-02-10 15:55

I am working on a C# 4.0, WPF 4.0, SQL 2008 project and I do work at home and in the office. I just setup SubVersion using Visual SVN per the recommendations found in other ques

7条回答
  •  既然无缘
    2021-02-10 16:31

    you can use settings to define more than one connection string. just double-click Settings.settings from Solution Explorer->project->Properties. then you will see the combobox that contains types of settings. choose ConnectionString then enter the connstr.

    then you can get the connstr with below code

    using System.Configuration;
    
    using test.Properties;
    
    namespace test{
    public partial class mainForm : Form{
    
       public mainForm()
    
        {
            InitializeComponent();            
    
        }
    
        private void mainForm_Load(object sender, EventArgs e)
        {
            string connectionStr = ConfigurationManager.ConnectionStrings[this_index_is_up_to your_algorithm].ToString();
        }
    }
    

    }

提交回复
热议问题