-1
SqlCeConnection cs = new SqlCeConnection(@"Data Source=C:\Users\Shahid\Documents\Visual Studio 2010\Projects\DarUlIfta\DarUlIfta\DB.sdf");

This works fine with complete path

But only problem I'm facing when I use relative path my database stop saving data into it. While at run time it works fine when I close the app there is noting in the database. What should I do?

3
  • Confirm the path the app is actually running from. You might be looking in the wrong file. Commented Aug 23, 2012 at 14:50
  • Jsobo if i use the relative path string instead of this it retrieves the data but only data base dose not store the value Commented Aug 23, 2012 at 15:38
  • ok lets assume you have the database file in 2 locations... and you actually open and write to database at location #1 but then open the database at location #2 and can't find your records. If this happened and I told you to look in location #1 silly... you would face-palm. Actually this is what I am suggesting could be happening here. Commented Aug 23, 2012 at 18:01

1 Answer 1

0

Your connection string is to a database inside your project source folder. That is not right; when you deploy software you do not deploy your source code. You have to determine the path to your deployed data. There are several ways to do this, depending on information which you have not shown us.

As a first guess, try this:

SqlCeConnection cs = new SqlCeConnection(@"Data Source=|DataDirectory|\DB.sdf");

If that works, you have to learn about deployment properties. If that doesn't work, we will need a lot more information about what you are trying to do.

Also, consult Using a database in .NET.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.