title: How to save data to a database when it's attached as service-based database?
body: <p>I attached the service-based database to my windows application and I used the following code to save the data, it is working correctly, but when I close the application and open again the data which I saved was cleared automatically.</p>
  
  <p>How to save the data permanently...</p>
  
  <pre><code>string c = Application.StartupPath + "\\Stock.mdf";
  SqlConnection con = new SqlConnection(@"AttachDbFilename='"+c+"';Integrated Security=True;Connect Timeout=30;User Instance=True");
  
  con.Open();
  
  SqlCommand cmd = new SqlCommand("Insert into Codedetails values('TF','" + txt_productcode.Text + "','" + txt_productname.Text + "','" + txt_brandcode.Text + "','" + txt_brandname.Text + "')", con);
  cmd.ExecuteNonQuery();
  con.Close();
  </code></pre>