KhDonen
KhDonen

Reputation: 289

Why SQL Server CE does not recognize DB when my app is deployed

I am struggling with how to make my app work when deployed - it keeps saying the file is invalid no matter what I do: What I have now is:

Data Source="\MyDb.sdf"

The DB should be in the directory where the executable is located.

Upvotes: 1

Views: 34

Answers (1)

Pete Garafano
Pete Garafano

Reputation: 4913

You probably need to use an absolute path to access the file.

var pathToExe = System.Reflection.Assembly.GetExecutingAssembly().Location;
var path = Path.GetDirectoryName(pathToExe);
var pathToDb = Path.Combine(path, "MyDb.sdf");

pathToDb should now be an absolute path to your database object, assuming it is always in the directory of the executing assembly.

Upvotes: 2

Related Questions