views:

580

answers:

3

Hi, I have SQL Ce db in my app, which is included in my app directory. While debugging its OK, but when published and run with setup.exe, it retrieves "file not found" in temporary directory the app is ran from. I would like to run from standard location, but I dont know how to change it.

I am using this string:

SqlCeConnection connection = new SqlCeConnection("Data Source=database.sdf;Persist Security Info=False;");

When I run setup.exe, the app never starts, stating that in its temporary directory the db file was not found. When I run app.exe, it works. I do not understand it...:(

EDIT: I can see that in the VS project settings, there is connection string and there is "Data Source=|DataDirectory|\Database.sdf"

The path should be something like local directory? Thanks!

A: 

In your Set up application select the application go to it's properties. there you can mention the Manufacturer Name and Product Name and it will use C:\Program Files\ManufacturerName\ProductName. In this path u add our .sdf file and you can use this path . To make it more flexible add an app.config file and mention the connection string over there and use that Connection string using ConfigurationManager's ConnectionStrings settings. ex:

string ConString = ConfigurationManager.ConnectionStrings["ConnectStirng"].ToString();

and now use this connectionstring in your application so if you need to edit you can change every where...

jankhana
A: 

Build your connection string dynamically. Something like this:

string connString = string.Format("Data Source={0}; Persist Security Info=False;",
    Path.Combine(Application.StartupPath, "database.sdf"));
ctacke
A: 

string connectionString = ("Data Source=" + (System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)) + "E:\delta\test\MyDatabase#1.sdf;Persist Security Info=False;");

my db in mobile not my computer i need to connect to this data base please send answer to me

bahaa