1

I am using MDF file for database in windows form for that purpose I have to write the full path in the connection string i.e.

Data Source=`(LocalDB)\v11.0;AttachDbFilename="C:\Users\adeel\Documents\Visual Studio 2013\Projects\WPFwithSampleDB\WPFwithSampleDB\Database1.mdf";Integrated Security=True

I want to change this path of AttachDbFilename as user install my program in their machine, I changed this path to

(LocalDB)\v11.0;AttachDbFilename="Database1.mdf";Integrated Security=True

But it does not work

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Taimur Adil
  • 77
  • 1
  • 10

1 Answers1

2

Try |DataDirectory|. It eliminates the need to hard-code the full path and also makes it easy to share a project and also to deploy an application. Like this:

AttachDbFilename=|DataDirectory|\Database1.mdf;

Have a look at this: Working with local databases.

Salah Akbari
  • 39,330
  • 10
  • 79
  • 109