asp.net mvc - Unable to connect to SQL Server database exception on Roles.IsUserInRole("Admin") -


i

unable connect sql server database

exception on line

isadmin = roles.isuserinrole("admin") 

detailed inner exception is:

a network-related or instance-specific error occurred while establishing connection sql server. server not found or not accessible. verify instance name correct , sql server configured allow remote connections.

i using asp.net mvc identity. , using ef data first approach. web.config connection string is:

<connectionstrings>     <add name="defaultconnection"           connectionstring="data source=(localdb)\v11.0;attachdbfilename=|datadirectory|\aspnet-inspinia_mvc5_seedproject-20141215093835.mdf;initial catalog=aspnet-inspinia_mvc5_seedproject-20141215093835;integrated security=true"            providername="system.data.sqlclient" />     <add name="entities"           connectionstring="metadata=res://*/models.model1.csdl|res://*/models.model1.ssdl|res://*/models.model1.msl;provider=system.data.sqlclient;provider connection string=&quot;data source=(localdb)\v11.0;attachdbfilename=|datadirectory|\aspnet-inspinia_mvc5_seedproject-20141215093835.mdf;initial catalog=aspnet-inspinia_mvc5_seedproject-20141215093835;integrated security=true;multipleactiveresultsets=true;app=entityframework&quot;"           providername="system.data.entityclient" /> </connectionstrings> <appsettings>     <add key="enablesimplemembership" value="false" />     <!-- others --> </appsettings> 

to initiallize simple membership, wrote following class in global.asax.cs

[attributeusage(attributetargets.class | attributetargets.method, allowmultiple = false, inherited = true)] public sealed class initializesimplemembershipattribute : actionfilterattribute {     private static simplemembershipinitializer _initializer;     private static object _initializerlock = new object();     private static bool _isinitialized;      public override void onactionexecuting(actionexecutingcontext filtercontext)     {         lazyinitializer.ensureinitialized(ref _initializer, ref _isinitialized, ref _initializerlock);     }      private class simplemembershipinitializer     {         public simplemembershipinitializer()         {             try             {                 websecurity.initializedatabaseconnection("defaultconnection", "userprofile", "id", "username", autocreatetables: true);             }             catch (exception ex)             {                 throw new invalidoperationexception("something wrong", ex);             }         }     } } 


Comments