SqlCeConnection relative path for connection string fails

百般思念 提交于 2019-12-04 06:54:22

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/12093962/sqlceconnection-relative-path-for-connection-string-fails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!