Relative SqlCeConnection path for connection string not running

SqlCeConnection cs = new SqlCeConnection(@"Data Source=C:\Users\Shahid\Documents\Visual Studio 2010\Projects\DarUlIfta\DarUlIfta\DB.sdf");

It works great with the full path

But only the problem that I encounter when I use the relative path, my database stops saving data. Although while working, it works fine when I close the application that is marked in the database. What should I do?

-1
source share
1 answer

The connection string is the database in the source folder of the project. It is not right; when you deploy software, you do not deploy source code. You must determine the path to the expanded data. There are several ways to do this, depending on the information that you did not show us.

As you might guess, try the following:

SqlCeConnection cs = new SqlCeConnection(@"Data Source=|DataDirectory|\DB.sdf");

, . , , .

, .NET.

0

All Articles