0

我无法弄清楚为什么会收到此错误消息:

A network-related or instance-specific error occurred while establishing a connection to 
SQL Server. The server was not found or was not accessible. Verify that the instance name
is correct and that SQL Server is configured to allow remote connections. (provider: SQL
Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

我有一个简单的成员资格和角色管理器设置并正常工作,如下所示:

<connectionStrings>
  <add name="GustaafConnectionString" connectionString="Data Source=ROBBIE-PC\PHL;Initial Catalog=Gustaaf;Integrated Security=True" providerName="System.Data.SqlClient"/>
</connectionStrings>

<authentication mode="Forms">
  <forms timeout="1440" protection="All" slidingExpiration="true"/>
</authentication>
<anonymousIdentification enabled="true"/>

<roleManager enabled="true" defaultProvider="RoleProvider">
  <providers>
    <add connectionStringName="GustaafConnectionString" applicationName="Gustaaf" name="RoleProvider" type="System.Web.Security.SqlRoleProvider"/>
  </providers>
</roleManager>

<membership defaultProvider="MembershipProvider">
  <providers>
    <clear/>
    <add name="MembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="GustaafConnectionString" 
         applicationName="Gustaaf" enablePasswordRetrieval="true" enablePasswordReset="false" requiresQuestionAndAnswer="true" 
         requiresUniqueEmail="false" passwordFormat="Encrypted"/>
  </providers>
</membership>

这很好,但错误发生在这里:

<profile>
  <properties>
    <add
      name="numberOfVisits"
      type="Int32"
      defaultValue="0"
      allowAnonymous="true" />
    <group name="Address">
      <add name="City"
           defaultValue="NA"/>
      <add name="PostalCode" 
           type="Int32"
           defaultValue="0"/>
      <add name="Street"
           defaultValue="NA" />
      <add name="Number" 
           type="Int32"
           defaultValue="0" />
    </group>
    <add name="PhoneNumber"
         defaultValue="NA"/>
    <add name="DateOfBirth" type="DateTime"
         defaultValue="GetDate()"/>
  </properties>
</profile>

一旦我尝试从网站(例如母版页)访问这些属性,我就会收到上面的错误消息。这就是我正在做的事情:

protected void Page_PreRender()
{
    if (Profile.IsAnonymous)
    {
        Profile.numberOfVisits++;
    }
}

有人可以向我解释为什么我会收到此消息吗?

4

1 回答 1

1

您需要像为角色/成员所做的那样为配置文件定义一个提供者,所以像这样 -

<profile defaultProvider="SqlProvider">
    <providers>
    <clear/>
    <add name="SqlProvider"
        type="System.Web.Profile.SqlProfileProvider"
        connectionStringName="GustaafConnectionString"
        applicationName="Gustaaf" />
    </providers>
    <properties>
        <!-- Properties Here -->
    </properties>
</profile>

请参阅此处以获取完整参考http://msdn.microsoft.com/en-us/library/system.web.profile.sqlprofileprovider.aspx

于 2012-11-16T14:39:19.460 回答