I want to make a database for my mobile 6 cellphone app. What I did was in visual studios I went to my project name and right clicked on it, went to add -> add new item -> data -> choose datafile.
It created a database file called “AppDatabase1.sdf”
Now I want to connect to my database but I don’t know how what the connection string is since I see no app.config where I normally would expect it to be.
So I just have
SqlCeConnection conn = new SqlCeConnection("Not sure what to put here");
conn.Open();
When I click on the server explorer tab I see my database so I click on it. In the properties section it has something labeled “connection string” however it looks like the path to the actual file and when I run it in the emulator I get an error.
“The database file cannot be found.
Check the path to the database.”
Thanks
You don’t have to create the database outside your application. It is probably better if you had a fail-safe so that if the user accidentally deletes it or it does not exist, then you can re-create it easily. This is good for initial installations. The following code will do what you want (SQLCE/Mobile 2005 example):