插入错误:文件的目录查找

本文关键字:查找 文件 错误 插入 | 更新日期: 2023-09-27 18:30:49

>我的网站上有一个用VS2010构建的注册页面,当我在点击注册中填写表格时,我收到以下错误。帮助将不胜感激。

System.Exception was unhandled by user code
      Message=Insert Error:Directory lookup for the file "C:'Users'myname'Documents'myname'Project'App_Data'SJDatabase.mdf" failed with the operating system error 5(error not found).
    Cannot attach the file 'C:'Users'myname'Documents'myname'Project'App_Data'SJDatabase.mdf' as database 'SJDatabase'.

连接字符串:

<connectionStrings>
        <add name="ApplicationServices" connectionString="data source=.'SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|'aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient"/>
    <add name="MyConsString" connectionString="data source=.'SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|SJDatabase.mdf;
                             Initial Catalog=SJDatabase;
                             Integrated Security=SSPI;"
                             providerName="System.Data.SqlClient" />
  </connectionStrings>

插入错误:文件的目录查找

我认为您在|DataDirectory|'SJDatabase.mdf上缺少反斜杠

另外,您有两次集成安全性= SSPI,我认为您不需要AttachDBFileName部分

尝试更简单的操作,如下所示:

"data source=ServerName;Initial Catalog=SJDatabase;Integrated Security=SSPI" providerName="System.Data.SqlClient"