c# - Wrapping entity framework exceptions on Open -
if user under service running doesn't have access database, ef fail following exception:
system.data.entity.core.providerincompatibleexception: error occurred while getting provider information database. can caused entity framework using incorrect connection string. check inner exceptions details , ensure connection string correct.
here's inner exception (that has specific details):
system.data.entity.core.providerincompatibleexception: provider did not return providermanifesttoken string. ---> system.data.sqlclient.sqlexception: login failed user '[redacted]'. @ system.data.sqlclient.sqlinternalconnection.onerror(sqlexception exception, boolean breakconnection, action`1 wrapcloseinaction) @ system.data.sqlclient.tdsparser.throwexceptionandwarning(tdsparserstateobject stateobj, boolean callerhasconnectionlock, boolean asyncclose) @ system.data.sqlclient.tdsparser.tryrun(runbehavior runbehavior, sqlcommand cmdhandler, sqldatareader datastream, bulkcopysimpleresultset bulkcopyhandler, tdsparserstateobject stateobj, boolean& dataready) @ system.data.sqlclient.tdsparser.run(runbehavior runbehavior, sqlcommand cmdhandler, sqldatareader datastream, bulkcopysimpleresultset bulkcopyhandler, tdsparserstateobject stateobj) @ system.data.sqlclient.sqlinternalconnectiontds.completelogin(boolean enlistok) @ system.data.sqlclient.sqlinternalconnectiontds.attemptonelogin(serverinfo serverinfo, string newpassword, securestring newsecurepassword, boolean ignoresniopentimeout, timeouttimer timeout, boolean withfailover) @ system.data.sqlclient.sqlinternalconnectiontds.loginnofailover(serverinfo serverinfo, string newpassword, securestring newsecurepassword, boolean redirecteduserinstance, sqlconnectionstring connectionoptions, sqlcredential credential, timeouttimer timeout) @ system.data.sqlclient.sqlinternalconnectiontds.openloginenlist(timeouttimer timeout, sqlconnectionstring connectionoptions, sqlcredential credential, string newpassword, securestring newsecurepassword, boolean redirecteduserinstance) @ system.data.sqlclient.sqlinternalconnectiontds..ctor(dbconnectionpoolidentity identity, sqlconnectionstring connectionoptions, sqlcredential credential, object providerinfo, string newpassword, securestring newsecurepassword, boolean redirecteduserinstance, sqlconnectionstring userconnectionoptions, sessiondata reconnectsessiondata) @ system.data.sqlclient.sqlconnectionfactory.createconnection(dbconnectionoptions options, dbconnectionpoolkey poolkey, object poolgroupproviderinfo, dbconnectionpool pool, dbconnection owningconnection, dbconnectionoptions useroptions) @ system.data.providerbase.dbconnectionfactory.createpooledconnection(dbconnectionpool pool, dbconnection owningobject, dbconnectionoptions options, dbconnectionpoolkey poolkey, dbconnectionoptions useroptions) @ system.data.providerbase.dbconnectionpool.createobject(dbconnection owningobject, dbconnectionoptions useroptions, dbconnectioninternal oldconnection) @ system.data.providerbase.dbconnectionpool.usercreaterequest(dbconnection owningobject, dbconnectionoptions useroptions, dbconnectioninternal oldconnection) @ system.data.providerbase.dbconnectionpool.trygetconnection(dbconnection owningobject, uint32 waitformultipleobjectstimeout, boolean allowcreate, boolean onlyonecheckconnection, dbconnectionoptions useroptions, dbconnectioninternal& connection) @ system.data.providerbase.dbconnectionpool.trygetconnection(dbconnection owningobject, taskcompletionsource`1 retry, dbconnectionoptions useroptions, dbconnectioninternal& connection) @ system.data.providerbase.dbconnectionfactory.trygetconnection(dbconnection owningconnection, taskcompletionsource`1 retry, dbconnectionoptions useroptions, dbconnectioninternal oldconnection, dbconnectioninternal& connection) @ system.data.providerbase.dbconnectioninternal.tryopenconnectioninternal(dbconnection outerconnection, dbconnectionfactory connectionfactory, taskcompletionsource`1 retry, dbconnectionoptions useroptions) @ system.data.sqlclient.sqlconnection.tryopeninner(taskcompletionsource`1 retry) @ system.data.sqlclient.sqlconnection.tryopen(taskcompletionsource`1 retry) @ system.data.sqlclient.sqlconnection.open() @ system.data.entity.sqlserver.defaultsqlexecutionstrategy.<>c__displayclass1.<execute>b__0() @ system.data.entity.sqlserver.defaultsqlexecutionstrategy.execute[tresult](func`1 operation) @ system.data.entity.sqlserver.sqlproviderservices.usingconnection(dbconnection sqlconnection, action`1 act) @ system.data.entity.sqlserver.sqlproviderservices.usingmasterconnection(dbconnection sqlconnection, action`1 act) @ system.data.entity.sqlserver.sqlproviderservices.getdbprovidermanifesttoken(dbconnection connection) @ system.data.entity.core.common.dbproviderservices.getprovidermanifesttoken(dbconnection connection) --- end of inner exception stack trace --- @ system.data.entity.core.common.dbproviderservices.getprovidermanifesttoken(dbconnection connection) @ system.data.entity.utilities.dbproviderservicesextensions.getprovidermanifesttokenchecked(dbproviderservices providerservices, dbconnection connection)
the issue pretty clear: user doesn't have access. isn't clear, though, database we're trying open. when have several databases (several dbcontexts) being used in span of 1 call, want know database rejecting user, , want know , easily.
as such, looking way override opening of connection, can catch exception , wrap more information. however, don't see easy way this, since dbcontext
uses dbconnection
. how hook process wrap connection opening? or there better way information i'm trying do?
the exception doesn't give me useful stack trace, since service async
.
the inner exception has of details may require. base exception in case sqlexception
try { //code fires error } catch (providerincompatibleexception ex) { sqlexception baseexception = ex.getbaseexception() sqlexception; console.writeline(baseexception.server); }
you can log additional information wherever catching exception.
Comments
Post a Comment