title: WPF C# : How to set Dynamic Connection String of SQL Server local database
body: <p>I want to deploy my WPF project but at the client machine it throws an exception that connection is not able to open.</p>
  
  <p>I use a hardcoded string I don't know how to set dynamic connection string which changes at every computer. Someone please guide me with deployment of a WPF project with local SQL Server database or how to set connection string dynamically.</p>
  
  <p><strong>What I have done:</strong></p>
  
  <ol>
  <li>Deploy and export database with .EXE</li>
  <li>Deploy without database and with SQL script so on the client machine it creates database before starting setup</li>
  </ol>
  
  <p>This is the connection string which I am using:</p>
  
  <pre><code>&lt;add name="connect"
       connectionString="Data Source=(LocalDB)\FoodManagmentUpdate;AttachDbFilename=C:\Program Files (x86)\SolBuz\Shreeji Snacks\FoodManagmentUpdate.mdf;Integrated Security=True"
       providerName="System.Data.SqlClient" /&gt;
  </code></pre>
  
  <p>I already tried with : </p>
  
  <pre><code>&lt;add name="connect"
       connectionString="Data Source=(LocalDB)\FoodManagmentUpdate;AttachDbFilename=|Data Dictionary|FoodManagmentUpdate.mdf;Integrated Security=True"
       providerName="System.Data.SqlClient" /&gt;
  </code></pre>
  
  <p>I installed <code>SqlLocalDb</code> on my client's machine, but still it won't work. And <code>FoodManagmentUpdate</code> is the object of <code>SqlLocalDb</code> which I also created on the client computer.</p>