asp.net mvc 4 - MVC Application not accessing SQL Server database -


i getting error in deployed mvc 4 web application, whenever click link requires database access:

object reference not set instance of object.

description: unhandled exception occurred during execution of current web request. please review stack trace more information error , originated in code.

exception details: system.nullreferenceexception: object reference not set instance of object.

when run mvc app locally, through visual studio, connecting these remote databases, not error, , credentials correct because when "connect database" logs in , retrieves entities normal. published site server's ftp, host not have webdeploy service.

can explain why deployed app have issues database , not local version?

update

before exposed nullreferenceexception, reflectiontypeloadexception. don't know if means anything, here:

[reflectiontypeloadexception: unable load 1 or more of requested types. retrieve loaderexceptions property more information.] system.reflection.runtimemodule.gettypes(runtimemodule module) +0 system.reflection.runtimemodule.gettypes() +4 system.reflection.assembly.gettypes() +61 system.data.entity.modelconfiguration.mappers.typemapper.<.ctor>b_1(assembly a) +11 system.linq.d_142.movenext() +234 system.collections.generic.list1.insertrange(int32 index, ienumerable1 collection) +392 system.data.entity.modelconfiguration.mappers.typemapper..ctor(mappingcontext mappingcontext) +258 system.data.entity.dbmodelbuilder.maptypes(edmmodel model) +114 system.data.entity.dbmodelbuilder.build(dbprovidermanifest providermanifest, dbproviderinfo providerinfo) +112 system.data.entity.dbmodelbuilder.build(dbconnection providerconnection) +59 system.data.entity.internal.lazyinternalcontext.createmodel(lazyinternalcontext internalcontext) +62 system.data.entity.internal.retrylazy2.getvalue(tinput input) +123 system.data.entity.internal.lazyinternalcontext.initializecontext() +461 system.data.entity.internal.internalcontext.getentitysetandbasetypefortype(type entitytype) +18 system.data.entity.internal.linq.internalset1.initialize() +52 system.data.entity.internal.linq.internalset1.get_internalcontext() +15 system.data.entity.infrastructure.dbquery1.system.linq.iqueryable.get_provider() +37 system.linq.queryable.select(iqueryable1 source, expression1 selector) +66 prooptinteractive.controllers.servicecontroller.index() +115 lambda_method(closure , controllerbase , object[] ) +35 system.web.mvc.actionmethoddispatcher.execute(controllerbase controller, object[] parameters) +14 system.web.mvc.reflectedactiondescriptor.execute(controllercontext controllercontext, idictionary2 parameters) +182 system.web.mvc.controlleractioninvoker.invokeactionmethod(controllercontext controllercontext, actiondescriptor actiondescriptor, idictionary2 parameters) +27 system.web.mvc.async.<>c__displayclass42.<begininvokesynchronousactionmethod>b__41() +28 system.web.mvc.async.<>c__displayclass81.b__7(iasyncresult ) +10 system.web.mvc.async.wrappedasyncresult1.end() +50 system.web.mvc.async.asynccontrolleractioninvoker.endinvokeactionmethod(iasyncresult asyncresult) +32 system.web.mvc.async.<>c__displayclass39.<begininvokeactionmethodwithfilters>b__33() +58 system.web.mvc.async.<>c__displayclass4f.<invokeactionmethodfilterasynchronously>b__49() +225 system.web.mvc.async.<>c__displayclass37.<begininvokeactionmethodwithfilters>b__36(iasyncresult asyncresult) +10 system.web.mvc.async.wrappedasyncresult1.end() +50 system.web.mvc.async.asynccontrolleractioninvoker.endinvokeactionmethodwithfilters(iasyncresult asyncresult) +34 system.web.mvc.async.<>c_displayclass2a.b_20() +24 system.web.mvc.async.<>c_displayclass25.b_22(iasyncresult asyncresult) +99 system.web.mvc.async.wrappedasyncresult1.end() +50 system.web.mvc.async.asynccontrolleractioninvoker.endinvokeaction(iasyncresult asyncresult) +27 system.web.mvc.<>c__displayclass1d.<beginexecutecore>b__18(iasyncresult asyncresult) +14 system.web.mvc.async.<>c__displayclass4.<makevoiddelegate>b__3(iasyncresult ar) +23 system.web.mvc.async.wrappedasyncresult1.end() +55 system.web.mvc.controller.endexecutecore(iasyncresult asyncresult) +39 system.web.mvc.async.<>c_displayclass4.b__3(iasyncresult ar) +23 system.web.mvc.async.wrappedasyncresult1.end() +55 system.web.mvc.controller.endexecute(iasyncresult asyncresult) +29 system.web.mvc.controller.system.web.mvc.async.iasynccontroller.endexecute(iasyncresult asyncresult) +10 system.web.mvc.<>c__displayclass8.<beginprocessrequest>b__3(iasyncresult asyncresult) +25 system.web.mvc.async.<>c__displayclass4.<makevoiddelegate>b__3(iasyncresult ar) +23 system.web.mvc.async.wrappedasyncresult1.end() +55 system.web.mvc.mvchandler.endprocessrequest(iasyncresult asyncresult) +31 system.web.mvc.mvchandler.system.web.ihttpasynchandler.endprocessrequest(iasyncresult result) +9 system.web.callhandlerexecutionstep.system.web.httpapplication.iexecutionstep.execute() +9628700 system.web.httpapplication.executestep(iexecutionstep step, boolean& completedsynchronously) +155

update

ok attempted deploy brand new mvc app visual studio, , gave me no errors when trying access models (i made simple students model , created new "student" in database, not work in actual mvc app. ideas?

the table in database might not exist. facing same problem now, easiest way delete whole db , let ef recreate everything. if have sensitive data, trickier. , might try these too:

database.setinitializer(new dropcreatedatabaseifmodelchanges<yourdbcontext>()); //  or can use dropcreatedatabasealways<> 

from here: ef4 code first create new table
or can check one: entity framework 4.1 code first not creating tables


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -