I’m trying to establish a connection with a database in a Windows CE 5.0 application and I’m using the Compact Framework 2.0
The database is located inside the project’s folder:
C:\Documents and Settings\softdil\My Documents\Visual Studio 2008\Projects\Datalogic\Datalogic
These are the lines I’m using in order to connect and open the database:
SqlCeConnection conn = new SqlCeConnection();
conn.ConnectionString = "Data Source = Datalogic.sdf;";
conn.Open();
Which gives me a beautiful “database file not found” error message.
I also tried with the absolute uri with same results:
conn.ConnectionString = "Data Source = C:\\Documents and Settings\\softdil\\My Documents\\Visual Studio 2008\\Projects\\Datalogic\\Datalogic;";
What am I doing wrong here?
May be it has something to do with the aplication being debugged (executed) in the mobile device?
I don’t really think so because the database works when the application is loaded, meaning that is associated with a listbox and loads data correctly from the database.
In a Win CE application we use the following to get the full path of the executing file:
Using
StartupPathyou can then add your database name to that path and add it to the connection string: