Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF EF DB connection string : Error when using attached db in connection string
    text
    copied!<p><strong>THIS CONNECTION STRING WORKS</strong> </p> <p>On my Local system i was using the database connection string</p> <pre><code>&lt;connectionStrings&gt; &lt;add name="GaugeSelectorEntities" connectionString="metadata=res://*/Gage.csdl|res://*/Gage.ssdl|res://*/Gage.msl;provider=System.Data.SqlClient;provider connection string=&amp;quot;Data Source=GEORGE1\SQL08R2;Initial Catalog=GaugeSelector;Integrated Security=True;MultipleActiveResultSets=True&amp;quot;" providerName="System.Data.EntityClient" /&gt; &lt;/connectionStrings&gt; </code></pre> <p>This works perfectly fine.</p> <p><strong>CHANGED TO ATTACH DB FILE INSTEAD AND IT THROWS ERROR</strong></p> <p>Now i have to deploy the WPF application and so i want to attach the mdf file from the database. So as suggested from existing resources on web i change the string to</p> <pre><code>&lt;connectionStrings&gt; &lt;add name="GaugeSelectorEntities" connectionString="metadata=res://*/Gage.csdl|res://*/Gage.ssdl|res://*/Gage.msl;provider=System.Data.SqlClient;provider connection string=&amp;quot;Data Source=GEORGE1\SQL08R2;AttachDbFilename=|DataDirectory|\DB\GaugeSelector.mdf;Initial Catalog=GaugeSelector;Integrated Security=True;MultipleActiveResultSets=True&amp;quot;" providerName="System.Data.EntityClient" /&gt; &lt;/connectionStrings&gt; </code></pre> <p>The only change being</p> <pre><code>AttachDbFilename=|DataDirectory|\DB\GaugeSelector.mdf; </code></pre> <p>I infact copied the mdf file of database from it's location to a folder DB in the executable path. By the way i was using LINQ to EF. But now i start getting the error. </p> <pre><code>{"The underlying provider failed on Open."} </code></pre> <p>Now i read somewehere it might happen if object context is not opened. So i put</p> <pre><code>GSData.Connection.Open(); </code></pre> <p>But now it breaks here with the same error. Is my approach itself wrong (Then what should be the approach) or do i just need some minor corrections on the connection string?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload