0

<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->

<configuration>
  <connectionStrings>
    <add name="ApplicationServices"
         connectionString="data source=&quot;Localhost\SQLEXPRESS&quot;;
         Initial Catalog=Saqib;Integrated Security=SSPI;
         AttachDBFilename=|D:\SAQIB|\aspnetdb.mdf;
         User Instance=true; User ID=sa;Password=angel"
         providerName="System.Data.SqlClient" />
  </connectionStrings>

  <system.web>
    <compilation debug="false" strict="false" explicit="true" targetFramework="4.0" />

    <authentication mode="Forms">
      <forms loginUrl="~/Account/Login.aspx" timeout="2880" />
    </authentication>

    <membership>
      <providers>
        <clear/>
        <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices"
             enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false"
             maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10"
             applicationName="/" />
      </providers>
    </membership>

    <profile>
      <providers>
        <clear/>
        <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/>
      </providers>
    </profile>

    <roleManager enabled="false">
      <providers>
        <clear/>
        <add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/" />
        <add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />
      </providers>
    </roleManager>

  </system.web>

  <system.webServer>
     <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
</configuration>

我创建了一个connectionstring访问 localhost 数据库。我的代码在下面请建议我它是否正确?因为当我在浏览器上运行我的登录页面时,它给出了这个错误:

Server Error in '/SAQIB1' Application.
Invalid value for key 'attachdbfilename'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
Exception Details: System.ArgumentException: Invalid value for key 'attachdbfilename'.
Source Error: 
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
4

1 回答 1

0

通常当你指定 db 文件名时,你会使用 |DataDirectory| 占位符。它是一个替换字符串,用于表示您的 db 文件的位置,如下所示:

"AttachDBFilename=|DataDirectory|database.mdf;"

在您的情况下,您正在指定自己的值而不是使用 DataDirectory,因此排除 | 字符和您的设置将是:

AttachDBFilename=D:\SAQIB\aspnetdb.mdf;
于 2013-07-12T06:55:38.993 回答