0

我在 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>
4

1 回答 1

1

我认为您缺少反斜杠|DataDirectory|\SJDatabase.mdf

此外,您有两次 Integrated Security=SSPI,我认为您不需要 AttachDBFileName 部分

尝试一些更简单的方法:

"data source=ServerName;Initial Catalog=SJDatabase;Integrated Security=SSPI" providerName="System.Data.SqlClient"
于 2012-04-11T14:30:54.780 回答