locked
underlying provider failed to open when i changed the property of database "copy always" to " do no copy" RRS feed

  • Question

  • this is my connection string please check it . if something is wrong tell me ??

    < connectionStrings>

    < add name="ClassLibrary1.Properties.Settings.Database1ConnectionString" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True" providerName="System.Data.SqlClient" />

    < /connectionStrings>

    Saturday, November 29, 2014 7:20 AM

Answers

  • Hello waqar_nadir,

    After changing the property of database "copy always" to " do no copy", please check the bin folder to see if the copied database is deleted, as far as I know, the “do no copy” would delete the copied file and from your connection string, it seems will search the bin folder to find the database file while the file is not there anymore so it throws an error.

    A workaround is to provide an absolute path and use the original database rather than the copied one:

    …;attachdbfilename=D:\BMX\Project\2014\11\EntityFrameworks\DFs\Database1.mdf;…
    Regards.

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Fred Bao Tuesday, December 9, 2014 9:12 AM
    Monday, December 1, 2014 8:56 AM

All replies

  • underlying provider failed to open

    Well, you need to get the inner exception message that is going to tell you what is wrong by using a try/catch with an ex.ToString().

    http://msdn.microsoft.com/en-us/library/system.exception.tostring(v=vs.110).aspx

    Saturday, November 29, 2014 3:50 PM
  • Hello waqar_nadir,

    After changing the property of database "copy always" to " do no copy", please check the bin folder to see if the copied database is deleted, as far as I know, the “do no copy” would delete the copied file and from your connection string, it seems will search the bin folder to find the database file while the file is not there anymore so it throws an error.

    A workaround is to provide an absolute path and use the original database rather than the copied one:

    …;attachdbfilename=D:\BMX\Project\2014\11\EntityFrameworks\DFs\Database1.mdf;…
    Regards.

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Fred Bao Tuesday, December 9, 2014 9:12 AM
    Monday, December 1, 2014 8:56 AM