1

I use :

connectionString="metadata=res://*/DomainModel.csdl|res://*/DomainModel.ssdl|res://*/DomainModel.msl;
                  provider=System.Data.SqlClient;
                  provider connection string="
                  data source=.\SQLEXPRESS;
                  AttachDBFileName=|DataDirectory|MyDatabase.mdf;
              Database=MyDatabase;
              Trusted_Connection=True;
                  Integrated Security=SSPI;
              User Instance=True;
                  multipleactiveresultsets=True;
                  App=EntityFramework""
providerName="System.Data.EntityClient"/>

The database .mdf is in the same folder with the app .EXE and the application works fine.

But when I change the connection string to:

connectionString="metadata=res://*/DomainModel.csdl|res://*/DomainModel.ssdl|res://*/DomainModel.msl;
                       provider=System.Data.SqlClient;
                       provider connection string="
                       data source=.\SQLEXPRESS;
                       AttachDBFileName=|%appdata%|MyDatabase.mdf;
               Database=MyDatabase;
               Trusted_Connection=True;
                       Integrated Security=SSPI;
               User Instance=True;
                       multipleactiveresultsets=True;
                       App=EntityFramework""
     providerName="System.Data.EntityClient"/>

and pasted the .mdf to %appdata% folder, my app can't connect to the database.

Is there anything wrong with the connection string?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
ch0eb1t
  • 103
  • 8
  • 1
    This post will help you: http://stackoverflow.com/questions/15037937/appdata-in-connection-string-is-not-substituted-for-the-actual-folder – user1429899 Aug 10 '13 at 10:44

0 Answers0