简体   繁体   English

我不能没有失败地使用角色。 “发生与网络相关或特定于实例的错误”

[英]I can't use Roles without failing. “A network-related or instance-specific error occurred”

Hi I'm trying to use and understand Roles for the first time. 嗨,我正在尝试第一次使用和理解角色。 How can I resolve this? 我该如何解决这个问题? Do I need to add something to the WebConfig ? 我是否需要在WebConfig添加一些内容?

private static void CreateRoleIfNotExists(string role)
{
    if (!Roles.RoleExists(role)) // this line throws the error.
    {
        Roles.CreateRole(role);
    }  
}

Update, complete stacktrace inserted below: 更新,完成下面插入的stacktrace:

[SqlException (0x80131904): 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)] System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +4856727 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +194 System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, SqlConnection owningObject) +4867325 System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject) +90 System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart) +374 System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +225 System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +189 System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) +4868451 System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) +31 System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) +431 System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) +66 System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +499 System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +65 System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +117 System.Data.SqlClient.SqlConnection.Open() +122 System.Web.DataAccess.SqlConnectionHolder.Open(HttpContext context, Boolean revertImpersonate) +87 System.Web.DataAccess.SqlConnectionHelper.GetConnection(String connectionString, Boolean revertImpersonation) +221 System.Web.Security.SqlRoleProvider.RoleExists(String roleName) +478 System.Web.Security.Roles.RoleExists(String roleName) +73 dk.certifikat.Global.CreateRoleIfNotExists(String role)

If you use the standard .net membership providers and roleproviders you need to setup the aspnetdb 如果您使用标准的.net成员资格提供程序和角色提供程序,则需要设置aspnetdb

this can be done by a command from the commandprompt 这可以通过commandprompt中的命令来完成

aspnet_regsql aspnet_regsql

this can be found in you .net framework directory. 这可以在.net框架目录中找到。 If you did this. 如果你这样做了 You need to provide the application with an connectionstring to the database where the aspnetdb is running. 您需要为应用程序提供一个连接字符串,以指向运行aspnetdb的数据库。

more about this can be found here . 更多关于这一点可以在这里找到。

I also encountered this error. 我也遇到过这个错误。 I was following the example at http://www.asp.net/web-forms/tutorials/aspnet-45/getting-started-with-aspnet-45-web-forms/introduction-and-overview in which they also use Roles.RoleExists at some moment. 我在http://www.asp.net/web-forms/tutorials/aspnet-45/getting-started-with-aspnet-45-web-forms/introduction-and-overview上关注这个例子,他们也使用了Roles.Role在某个时刻出现。 When I ran the application locally with Visual Studio Express, everything worked fine. 当我使用Visual Studio Express在本地运行应用程序时,一切正常。 But when I tried to access the application via the web, I got the same connection error. 但是当我试图通过网络访问应用程序时,我得到了相同的连接错误。

Turned out I had to change the web.config file. 原来我不得不改变web.config文件。 I changed the DefaultProfileProvider, DefaultMembershipProvider and DefaultRoleProvider. 我更改了DefaultProfileProvider,DefaultMembershipProvider和DefaultRoleProvider。 I changed the connectionStringName attribute to the one I had added to the connectionStrings, namely: 我将connectionStringName属性更改为我添加到connectionStrings的属性,即:

<add name="WingtipToys" providerName="System.Data.SqlClient" connectionString="Server=.\SQLEXPRESS;Database=wingtiptoys;Integrated Security=False;User Id=wingtiptoys;Password=wingtiptoys;AttachDbFileName=|DataDirectory|wingtiptoys.mdf;Persist Security Info=False" />

For example, the DefaultMembershipProvider now looks like: 例如,DefaultMembershipProvider现在看起来像:

<add name="DefaultMembershipProvider" type="System.Web.Providers.DefaultMembershipProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="WingtipToys" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />

with connectionStringName="WingtipToys" instead of connectionStringName="DefaultConnection" with connectionStringName =“WingtipToys”而不是connectionStringName =“DefaultConnection”

And then everything worked fine. 然后一切正常。 This may not be the best solution, but I hope this answer can help somebody. 这可能不是最好的解决方案,但我希望这个答案可以帮助某人。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 发生与网络相关或特定于实例的错误 - A network-related or instance-specific error occurred SQL SERVER:发生与网络相关或特定于实例的错误 - SQL SERVER:A network-related or instance-specific error occurred 与网络相关或特定于实例的错误 - A network-related or instance-specific error 与网络有关或与实例有关的错误? - A network-related or instance-specific error? 得到错误“与SQL Server建立连接时发生与网络相关或特定于实例的错误…” - Getting error “A network-related or instance-specific error occurred while establishing a connection to SQL Server…” 建立…错误时发生与网络有关或特定于实例的错误:26 - A network-related or instance-specific error occurred while establishing … error: 26 如何超时“建立与SQL Server的连接时发生与网络有关或特定于实例的错误”错误 - How to timeout “A network-related or instance-specific error occurred while establishing a connection to SQL Server” error "出现错误:建立与 SQL Server 的连接时发生与网络相关或特定于实例的错误" - Getting error: A network-related or instance-specific error occurred while establishing a connection to SQL Server 本地数据库:“与 SQL Server 建立连接时发生与网络相关或特定于实例的错误。” - Local database: "A network-related or instance-specific error occurred while establishing a connection to SQL Server." 生产服务器部署上出现“与网络有关或特定于实例的错误。” - “A network-related or instance-specific error occurred..” on Production Server Deployment
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM