c# - MSSQLLocalDb - How to create custom authentication with localDb connection in ASP.Net MVC? -


i'm trying make own authentication service using mssqllocaldb. have used connection string instantiate local instance of identitydbcontext class.

connectionstring="data source=(localdb)\mssqllocaldb;attachdbfilename=|datadirectory|\aspnet-verisystems-20161025123601.mdf;initial catalog=aspnet-verisystems-20161025123601;integrated security=true;multipleactiveresultsets=true 

but whenever i'm publishing project iis localhost i'm unable execute login service. , error

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. (provider: sql network interfaces, error: 50 - local database runtime error occurred. cannot create automatic instance. see windows application event log error details.     ) stack trace:    [sqlexception (0x80131904): 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. (provider: sql network interfaces, error: 50 - local database runtime error occurred. cannot create automatic instance. see windows application event log error details. )]    system.data.sqlclient.sqlinternalconnectiontds..ctor(dbconnectionpoolidentity identity, sqlconnectionstring connectionoptions, sqlcredential credential, object providerinfo, string newpassword, securestring newsecurepassword, boolean redirecteduserinstance, sqlconnectionstring userconnectionoptions, sessiondata reconnectsessiondata, dbconnectionpool pool, string accesstoken, boolean applytransientfaulthandling) +1418    system.data.sqlclient.sqlconnectionfactory.createconnection(dbconnectionoptions options, dbconnectionpoolkey poolkey, object poolgroupproviderinfo, dbconnectionpool pool, dbconnection owningconnection, dbconnectionoptions useroptions) +470    system.data.providerbase.dbconnectionfactory.createpooledconnection(dbconnectionpool pool, dbconnection owningobject, dbconnectionoptions options, dbconnectionpoolkey poolkey, dbconnectionoptions useroptions) +70    system.data.providerbase.dbconnectionpool.createobject(dbconnection owningobject, dbconnectionoptions useroptions, dbconnectioninternal oldconnection) +945    system.data.providerbase.dbconnectionpool.usercreaterequest(dbconnection owningobject, dbconnectionoptions useroptions, dbconnectioninternal oldconnection) +114    system.data.providerbase.dbconnectionpool.trygetconnection(dbconnection owningobject, uint32 waitformultipleobjectstimeout, boolean allowcreate, boolean onlyonecheckconnection, dbconnectionoptions useroptions, dbconnectioninternal& connection) +1637    system.data.providerbase.dbconnectionpool.trygetconnection(dbconnection owningobject, taskcompletionsource`1 retry, dbconnectionoptions useroptions, dbconnectioninternal& connection) +117    system.data.providerbase.dbconnectionfactory.trygetconnection(dbconnection owningconnection, taskcompletionsource`1 retry, dbconnectionoptions useroptions, dbconnectioninternal oldconnection, dbconnectioninternal& connection) +267    system.data.providerbase.dbconnectioninternal.tryopenconnectioninternal(dbconnection outerconnection, dbconnectionfactory connectionfactory, taskcompletionsource`1 retry, dbconnectionoptions useroptions) +318    system.data.sqlclient.sqlconnection.tryopeninner(taskcompletionsource`1 retry) +132    system.data.sqlclient.sqlconnection.tryopen(taskcompletionsource`1 retry) +246    system.data.sqlclient.sqlconnection.open() +122    system.data.entity.infrastructure.interception.internaldispatcher`1.dispatch(ttarget target, action`2 operation, tinterceptioncontext interceptioncontext, action`3 executing, action`3 executed) +104    system.data.entity.infrastructure.interception.dbconnectiondispatcher.open(dbconnection connection, dbinterceptioncontext interceptioncontext) +442    system.data.entity.sqlserver.<>c__displayclass33.<usingconnection>b__32() +562    system.data.entity.sqlserver.<>c__displayclass1.<execute>b__0() +16    system.data.entity.sqlserver.defaultsqlexecutionstrategy.execute(func`1 operation) +229    system.data.entity.sqlserver.sqlproviderservices.usingmasterconnection(dbconnection sqlconnection, action`1 act) +916    system.data.entity.sqlserver.sqlproviderservices.createdatabasefromscript(nullable`1 commandtimeout, dbconnection sqlconnection, string createdatabasescript) +111    system.data.entity.sqlserver.sqlproviderservices.dbcreatedatabase(dbconnection connection, nullable`1 commandtimeout, storeitemcollection storeitemcollection) +203    system.data.entity.migrations.utilities.databasecreator.create(dbconnection connection) +129    system.data.entity.migrations.dbmigrator.ensuredatabaseexists(action mustsucceedtokeepdatabase) +172    system.data.entity.migrations.dbmigrator.update(string targetmigration) +110    system.data.entity.internal.databasecreator.createdatabase(internalcontext internalcontext, func`3 createmigrator, objectcontext objectcontext) +118    system.data.entity.database.create(databaseexistencestate existencestate) +284    system.data.entity.createdatabaseifnotexists`1.initializedatabase(tcontext context) +185    system.data.entity.internal.internalcontext.performinitializationaction(action action) +72    system.data.entity.internal.internalcontext.performdatabaseinitialization() +502    system.data.entity.internal.retryaction`1.performaction(tinput input) +177    system.data.entity.internal.lazyinternalcontext.initializedatabaseaction(action`1 action) +273    system.data.entity.internal.internalcontext.getentitysetandbasetypefortype(type entitytype) +38    system.data.entity.internal.linq.internalset`1.initialize() +77    system.data.entity.internal.linq.internalset`1.get_internalcontext() +21    system.data.entity.infrastructure.dbquery`1.system.linq.iqueryable.get_provider() +56    system.data.entity.queryableextensions.firstordefaultasync(iqueryable`1 source, expression`1 predicate, cancellationtoken cancellationtoken) +199    system.data.entity.queryableextensions.firstordefaultasync(iqueryable`1 source, expression`1 predicate) +163    microsoft.aspnet.identity.entityframework.<getuseraggregateasync>d__6c.movenext() +503    system.runtime.compilerservices.taskawaiter.throwfornonsuccess(task task) +14139120    system.runtime.compilerservices.taskawaiter.handlenonsuccessanddebuggernotification(task task) +62    microsoft.aspnet.identity.cultureawaiter`1.getresult() +48    microsoft.aspnet.identity.owin.<passwordsigninasync>d__29.movenext() +410    system.runtime.compilerservices.taskawaiter.throwfornonsuccess(task task) +14139120    system.runtime.compilerservices.taskawaiter.handlenonsuccessanddebuggernotification(task task) +62    verisystems.controllers.<login>d__11.movenext() +373    system.runtime.compilerservices.taskawaiter.throwfornonsuccess(task task) +14139120    system.runtime.compilerservices.taskawaiter.handlenonsuccessanddebuggernotification(task task) +62    system.web.mvc.async.taskasyncactiondescriptor.endexecute(iasyncresult asyncresult) +93    system.web.mvc.async.<>c__displayclass37.<begininvokeasynchronousactionmethod>b__36(iasyncresult asyncresult) +22    system.web.mvc.async.asynccontrolleractioninvoker.endinvokeactionmethod(iasyncresult asyncresult) +42    system.web.mvc.async.asyncinvocationwithfilters.<invokeactionmethodfilterasynchronouslyrecursive>b__3d() +72    system.web.mvc.async.<>c__displayclass46.<invokeactionmethodfilterasynchronouslyrecursive>b__3f() +386    system.web.mvc.async.asynccontrolleractioninvoker.endinvokeactionmethodwithfilters(iasyncresult asyncresult) +42    system.web.mvc.async.<>c__displayclass2b.<begininvokeaction>b__1c() +38    system.web.mvc.async.<>c__displayclass21.<begininvokeaction>b__1e(iasyncresult asyncresult) +186    system.web.mvc.async.asynccontrolleractioninvoker.endinvokeaction(iasyncresult asyncresult) +38    system.web.mvc.controller.<beginexecutecore>b__1d(iasyncresult asyncresult, executecorestate innerstate) +29    system.web.mvc.async.wrappedasyncvoid`1.callenddelegate(iasyncresult asyncresult) +65    system.web.mvc.controller.endexecutecore(iasyncresult asyncresult) +53    system.web.mvc.async.wrappedasyncvoid`1.callenddelegate(iasyncresult asyncresult) +36    system.web.mvc.controller.endexecute(iasyncresult asyncresult) +38    system.web.mvc.mvchandler.<beginprocessrequest>b__5(iasyncresult asyncresult, processrequeststate innerstate) +44    system.web.mvc.async.wrappedasyncvoid`1.callenddelegate(iasyncresult asyncresult) +65    system.web.mvc.mvchandler.endprocessrequest(iasyncresult asyncresult) +38    system.web.callhandlerexecutionstep.system.web.httpapplication.iexecutionstep.execute() +399    system.web.httpapplication.executestep(iexecutionstep step, boolean& completedsynchronously) +157 

i have used code implement identitydbcontext

 public class applicationuser : identityuser     {         public async task<claimsidentity> generateuseridentityasync(usermanager<applicationuser> manager)         {             // note authenticationtype must match 1 defined in cookieauthenticationoptions.authenticationtype             var useridentity = await manager.createidentityasync(this, defaultauthenticationtypes.applicationcookie);             // add custom user claims here             return useridentity;         }     }      public class applicationdbcontext : identitydbcontext<applicationuser>     {         public applicationdbcontext()             : base("defaultconnection", throwifv1schema: false)         {         }          public static applicationdbcontext create()         {             return new applicationdbcontext();         }     } 

i want know i'm doing wrong. following list of things have tried:

  1. i have tried configuring iis virtual directory no luck,i.e. tried changing application pool localsystem or localservice instead of applicationpoolidentity.

2.i changed virtual directory allow read & execute permissions both desktop users , iis hosts.

will appreciate help.

comparing connection string 1 here (that work):

data source=(localdb)\mssqllocaldb;attachdbfilename=|datadirectory|project.mdf 

there no backslash between | , data file name.


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -