Link to home
Start Free TrialLog in
Avatar of JoeBo747

asked on

Data Connection Error

Hi Experts

Running through a tutorial on SQL compact 2005 (see I have completed the project until the debug stage the I get an sqlce exception:

System.Data.SqlServerCe.SqlCeException was unhandled
  Message="The file name is not valid. Check the file name for the database. [ File name = |DataDirectory|\Northwind.sdf ]"
  Source="SQL Server 2005 Mobile Edition ADO.NET Data Provider" etc. &&&&..
Have I a missing reference, the project builds the data source exists and the connection tests properly.

Any Help appreciated,
Avatar of naspinski
Flag of United States of America image

shouldn't you be looking for the northwind.mdf?  it shows 'sdf'
"Your app needs to look for the sdf file somewhere on the device. Most people either use the same folder that the app is running from or a location on a storage card.",

"The path is not valid. Check the directory for the database.",
Avatar of JoeBo747


Thanks for your replies, I have downloaded the project companion files and these reside on the desktop, these files include the Northwind.sdf file which the tutorial walks throught making a connection to. As I read this(please correct me if I am wrong.)

connection instructions below:
Figure 5. Adding a connection

Select the file C:\Program Files\Microsoft Visual Studio 8\SmartDevices\SDK\SQL Server\Mobile\v3.0\Northwind.sdf in the file-selection dialog box and click Open to select the database.
On the Add Connection dialog, click Test Connection to verify that the database connection is setup properly. If the database file exists and SQL Server Compact Edition has been properly installed, then a dialog box informs you that the connection succeeded.
Click OK to dismiss the Test Connection Succeeded dialog box.
Click OK on the Add Connection dialog box now that you have successfully tested the connection.
You can now expand the Connection string on the Choose Your Data Connection dialog box to view the connection string that has been generated, as shown in Figure 6.

Do I also need the sdf file on the mobile device?

Avatar of gnoon
Flag of Thailand image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Make sure the sdf is a part of your project. Its Build Action should be set as Content and change the path in your code to something like "\Program Files\Your Project\Northwind.sdf".