我在想为什么我不能在ASP.NET web.config文件中使用自定义环境变量,就像这样?
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<add name="ConnectionName" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename='%MyProjectsFolder%\WebAppName\App_Data\Database1.mdf';User Instance=true" providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
我通过“开始”->“运行”检查了.mdf文件的路径是有效的。
当我运行我的C#代码连接数据库时,我收到以下错误:
试图附加一个自动命名的数据库文件%MyProjectsFolder%\WebAppName\App_Data\Database1.mdf失败。已存在同名数据库,或指定的文件无法打开,或位于UNC共享上。