I'm having some trouble in understanding why I'm unable to connect to a simple test database I created through code. The database shows under Solution Explorer; however, it throws a SqlCeException with "The database file cannot be found as soon as it tries to open the connection. Check the path to the database. [Data Source = test.sdf]". If I navigate to the projects location using Explorer I can clearly see the database file. Below is my code for testing this.
string connectionString = "Data Source=test.sdf;password=password;encrypt=true";
SqlCeEngine engine = new SqlCeEngine(connectionString);
engine.CreateDatabase();
SqlCeConnection conn = new SqlCeConnection(connectionString);
SqlCeCommand cmd = new SqlCeCommand();
cmd.CommandText = "SELECT * FROM Project";
conn.Open();
SqlCeResultSet resultSet = cmd.ExecuteResultSet(ResultSetOptions.Scrollable |
ResultSetOptions.Updatable);
this.bindingSource1.DataSource = resultSet;
Any ideas why it is unable to find the database when it is actually there within the project?