title: How can I load SQL data source from a TextBox in C#?
body: <p>I am developing a program where I need to make a settings form for my database connection. I stopped at how to set the connection string from textboxes. Here is my code:</p>
  
  <p>In the settings form:</p>
  
  <pre><code>public string adresa_servera()
          {    
              return textBox1.Text;
          }
  </code></pre>
  
  <p>The text in this textbox is: MICHAL-PC\SQLEXPRESS</p>
  
  <p>In my main Form I use: </p>
  
  <pre><code>db_nastavenia nastavenia = new db_nastavenia(); //db_nastavenia is the name of the settings Form
  
  string x = nastavenia.adresa_servera();
  
  SqlConnection databaza = new SqlConnection();
  databaza.ConnectionString = "Data Source=" + x + ";Initial Catalog=ZBERUDAJOVTEPLA;Persist Security Info=False;User ID=sa; password=diplomovka";
  </code></pre>
  
  <p>To x I load text from the textbox of the settings Form.</p>
  
  <p>When I try it by manually typing the connection string like this, it works well:</p>
  
  <pre><code>databaza.ConnectionString = "Data Source=MICHAL-PC\\SQLEXPRESS;Initial Catalog=ZBERUDAJOVTEPLA;Persist Security Info=False;User ID=sa; password=diplomovka";
  </code></pre>