使用 WPF 和实体框架时,我有一个 APP.CONFIG,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<connectionStrings>
<add name="DatabaseEntities" connectionString="metadata=res://*/Model.csdl|res://*/Model.ssdl|res://*/Model.msl;provider=System.Data.SqlServerCe.4.0;provider connection string="Data Source=%APPDATA%\Folder\Database.sdf"" providerName="System.Data.EntityClient" />
</connectionStrings>
</configuration>
使用此代码时,它总是会引发以下错误:
System.Data.EntityException: The underlying provider failed on Open. ---> System.Data.SqlServerCe.SqlCeException: The path is not valid. Check the directory for the database. [ Path = %APPDATA%\Folder\Database.sdf ]
当我从命令提示符运行路径“%APPDATA%\Folder\Database.sdf”时它工作正常,如果我删除“%APPDATA% 并硬编码路径它工作正常 - 所以它看起来就像 %APPDATA% 是只是没有被实际文件夹取代......
谢谢,