我无法弄清楚为什么我收到此错误消息:
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++;
}
}
有人可以向我解释为什么我收到这条消息吗?
答案 0 :(得分: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