Question

I have created an ASP.NET 3.5 Website and added mobile forms to it through third party templates (since the VS designer doesn't support the old templates anymore). Now I want to use some database handling in my application which will be tested using a Windows Mobile 6.0 emulator. I wrote the following code to create a database programmatically using SQL Server Compact CE 4.0:

SqlCeEngine engine = new SqlCeEngine("Data Source=Program Files\\Calculator\\Calc.sdf;password=abcd");
engine.CreateDatabase();

However, no matter how I tweak the path, I always get the error, "The path is not valid. Check the directory for the database". I have tried various combinations of the connection string but in vain. Nothing works.

EDIT: I have also seen various other threads here and elsewhere on this issue but nothing seems to solve the problem in this case. I even tried the other folders like My Documents as shown below but it didn't work:

SqlCeEngine engine = new SqlCeEngine("Data Source='\\My Documents\\Calculator\\Calc.sdf';password=abcd");

Please help, thanks in advance.

Was it helpful?

Solution

I received no answers but eventually figured it out myself. It seems that the .sdf is only being accessed from the local machine/server from where I am deploying my application. Therefore, the path will relate to the server, in this case, my local machine.

Thus for me, this is the code that worked successfully:

path = Server.MapPath("~/App_Data");

SqlCeEngine engine = new SqlCeEngine("Data Source='" + path + "\\Calculator.sdf';password=abcd");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top