title: Connection string for local database in C#
body: <p>Maybe it's repetitive but I googled and didn't find my answer.</p>
  
  <p>I developed a program by .net that has a local database (Express) that works excellently on my computer, but when I create a setup and installation, it can't insert or update and so on for example in <code>Delete()</code> method I have </p>
  
  <pre><code>try
  {
  }
  catch
  {
  }
  </code></pre>
  
  <p>in the <code>exe</code>file always goes to the <code>catch{}</code> section and I don't know why :((  </p>
  
  <p>This is my connection string:</p>
  
  <pre><code>Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;Connect Timeout=30
  </code></pre>
  
  <p>This is one of my methods for example:</p>
  
  <pre><code>private Boolean Delete(int id)
  {
      //String conString = "Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=C:\\Users\\Parnian\\documents\\visual studio 2017\\Projects\\Bank\\Bank\\Database.mdf;Integrated Security=True";
      SqlConnection sql = new SqlConnection(Connection);
      String sqll = "Delete FROM TblBank WHERE  Id =@id ";
  
      try
      {
          sql.Open();
  
          SqlCommand cmd = new SqlCommand(sqll, sql);
          cmd.Parameters.AddWithValue("id", id);
          cmd.CommandType = System.Data.CommandType.Text;
  
          cmd.ExecuteNonQuery();
  
          sql.Close();
          return true;
      }
      catch (Exception ex)
      {
          MessageBoxEx.Show("have some problem", "wrong", MessageBoxButtons.OK, MessageBoxIcon.Error);
          return false;
      }
  }
  </code></pre>
  
  <p>and Necessary say i put my <code>.mdf</code> and <code>.ldf</code> file into my setup folder and make setup by Visual Studio Installer</p>