如何设置到SQL Server Compact数据库的相对路径? [英] How to set a relative path to a SQL Server Compact database?

查看:616
本文介绍了如何设置到SQL Server Compact数据库的相对路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样写的路径,一个紧凑的数据库,因此它会为大家对项目工作的工作?

How do I write the path to a compact database so it will work for everyone working on the project?

我的本地路径看起来是这样的:

My local path looks something like this:

SqlCeConnection con = 
    new SqlCeConnection(@"Data Source=C:\Users\Name\Documents\Visual Studio 2012\Projects\Unwanted\Local\Path\App_Data\Databas.sdf");



我想我已经看到人们用〜符号做这样的东西,总之我想进行此连接可行的每一个人,无论其映射的样子。

I think I've seen people use "~" sign to do stuff like this, anyhow I want to make this connection viable for everyone no matter how their mapping looks like.

希望我自己清楚! :)

Hope I made myself clear! :)

推荐答案

代字号()的 ASP.NET 以表示网站的根 - 它不能然而一个SQL Server CE连接字符串中使用

The tilde (~) is used in ASP.NET to denote the root of the web site - it cannot however be used in a SQL Server CE connection string.

您可以尝试只用

SqlCeConnection con = 
    new SqlCeConnection(@"Data Source=App_Data\Database.sdf");



然后,.NET应用程序将寻找到当前目录(从那里它已经开始了 - 通常在(项目目录)\bin\debug 文件夹)为的App_Data 文件夹和一个该文件夹内Database.sdf 文件。

Then the .NET app will look into the current directory (from where it's been started - often the (project dir)\bin\debug folder) for a App_Data folder and for a Database.sdf file inside that folder.

这篇关于如何设置到SQL Server Compact数据库的相对路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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