Reputation: 11
I have an application that implements SimpleMembership
which was modelled on the MVC Template
in Visual Studio 2012. I'm using an SQL Server CE (4)
database as the membership provider and have configured both web.config
and in InitializeSimpleMembershipAttribute
. The initializer
create the database
and add my custom users and roles and also the Account controller
allow users to register and login. However, whenever I try to progrmatically interrogate the membership provider e.g. User.IsInRole(<rolename>)
and I get an SQL connection error.
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)
This error isn't consistent as request succeeds sometimes but only on start up of the local machine. If I recompile the error is thrown and only a re-start will sometimes cure the problem. I have the application pool identity set to a local user with Administrator privileges
. I'm using SQL Server CE
for other databases in the application and they all work just fine.
I have even created a new MVC 4 application
using the VS template
and that has the same problem. I am at a loss on how to proceed to find the cause of the error or implement a fix.
Any help would be gratefully received.
Upvotes: 1
Views: 441
Reputation: 3213
I had the same issue, unfortunatelly you cannot check for roles with the usual User.IsInRole API because that still uses standard provider. I found that SimpleRoleProvider exposes GetRolesForUser so you can check if user is in role like this:
Roles.GetRolesForUser("mercury2269").Contains("Admin")
Upvotes: 1