title: How to establish database(SQL) Connection using c#?
body: <p>I want to establish a database connection for receiving the details of the customers using C#. I am using sql-server 2008 along with visual studio 2010.....</p>
  
  <p>Here is this code:</p>
  
  <pre><code>&lt;asp:Textbox id="TxtBox1" runat="server" /&gt;
  &lt;asp:Textbox id="TxtBox2" runat="server" /&gt;
  &lt;asp:Button id="Button1" runat="server" Onclick="Button1_Click" /&gt;
  </code></pre>
  
  <p>and the codebehind:</p>
  
  <pre><code>protected void Button1_Click(Object sender,EventArgs e)
  {
  string Text1=TextBox1.Text;
  string Text2=TextBox2.Text;
  string connectionString="Data Source=servername;InitialCatalog=DataBaseNameUserID=sa;  Password=YourPassword;"
  
  SqlConnection sqlConnection=new SqlConnection(connectionString);
  
  string insertStatement="INSERT INTO TableName(column1,column2) VALUES Txtb1+","+Txtb2";
  
  SqlCommand sqlCommand=new SqlCommand(insertStatement,sqlConnection);
  
  try
  {
  sqlConnection.Open();
  sqlCommand.ExecuteNonQuery();
  
  }
  finally
  {
  sqlConnection.Close();
  }
  
  
  }
  </code></pre>
  
  <p>I have created the data.mdf file in it i have created table containing fields but i am getting Connection has not established error can any one help me to resolve my problem??? </p>