的SqlCeConnection的连接字符串相对路径出现故障 [英] SqlCeConnection relative path for connection string fails

查看:402
本文介绍了的SqlCeConnection的连接字符串相对路径出现故障的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

这正常工作与完整路径

但是当我使用相对路径我的数据库停止保存数据到它唯一的问题,我面对的问题。虽然在运行时能正常工作,当我关闭该应用程序有注意到在数据库中。我该怎么办?

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?

推荐答案

您的连接字符串就是你的项目的源文件夹中的数据库。这是不正确的;当你部署的软件,你不部署源$ C ​​$ C。你必须确定你的部署数据的路径。有几种方法可以做到这一点,这取决于信息你所未示出我们

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.

此外,咨询在.NET中使用的数据库。

Also, consult Using a database in .NET.

这篇关于的SqlCeConnection的连接字符串相对路径出现故障的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆