SqlServerCe文件名无效
问题描述:
我使用VS 2010为Outlook 2010创建了一个加载项。我正在四处寻找存储数据的方式,并且我看到一群人在建议Sql CE。我尝试过了,并不停地遇到了此问题 文件名是无效的:数据源= | DataDirectory目录| \ data.sdfSqlServerCe文件名无效
string conString = Properties.Settings.Default.dataConn;
SqlCeConnection dbConn = new SqlCeConnection(conString);
try
{
using (SqlCeConnection con = new SqlCeConnection(conString))
{
con.Open();
}
}
catch(Exception e)
{
MessageBox.Show(e.ToString());
}
我这里使用的显示教程: http://www.dotnetperls.com/sqlce
任何帮助不胜感激!
谢谢。
答
| DataDirectory |是运行时扩展的连接字符串中的一个特殊变量。它扩展如下:
- For applications placed in a directory on the user machine, this will be the app's (.exe) folder.
- For apps running under ClickOnce, this will be a special data folder created by ClickOnce
- For Web apps, this will be the App_Data folder
这不适用于您的Outlook插件。我猜测它运行的上下文没有为它设置一个值。您可以尝试要么在连接字符串中提供了一个完整的数据库路径(更换| DataDirectory目录|)动态地使用在应用领域或设置DataDirectory目录的值如下:
AppDomain.CurrentDomain.SetData("DataDirectory", newpath)
具有看看Working with local databases更多信息。