1

I have an MVC5 web application which I usually develop using my laptop.

I am trying to get the app running on my main machine at home for home-working days but have a problem connecting to the local dev database on SQL Server - when I start the app I get the following error:

More info 30/11/16:

Note that the model is generated from EDML using Entity Developer

Unable to load the specified metadata resource. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

The solution consists of 2 projects, one of which is an entity model project which is generated from EDMX.

Note: On my main machine (where it isn't working) the connection string in Web.config is the same as the machine where it works except for Data Source which refers to the SQL Server name on the main machine - I have checked this is correct several times:

I have read several Stack Overflow posts with similar issues - most point to something wrong with the path to the csdl, ssdl, msl part of the connection string.

I have:

  • Checked the server name is correct in the connection string
  • Checked the database name is correct in the connection string
  • Checked the database exists and is available
  • Checked each of the three files are where the connection string says they are (they are)
  • Tried using wildcard in the connection string: res://*/dllname.csdl|res://*/dllname.ssdl|res://*/dllname.msl

Update 30/11/2016:

From the suggestions in this link I have:

  • Checked the MetadataArtifactProcessing property - it is not set to Copy to Output directory
  • Checked the connection string
  • We don't have a post-compile task

From the suggestion in this link I have tried setting the connection string connectionString="metadata=res://*/;

Stack Trace:

[MetadataException: Unable to load the specified metadata resource.]
   System.Data.Entity.Core.Metadata.Edm.MetadataArtifactLoaderResource.LoadResource() +85
   System.Data.Entity.Core.Metadata.Edm.MetadataArtifactLoaderResource.CreateReader() +10
   System.Data.Entity.Core.Metadata.Edm.MetadataArtifactLoaderResource.CreateReaders(DataSpace spaceToGet) +72
   System.Data.Entity.Core.Metadata.Edm.MetadataArtifactLoaderComposite.CreateReaders(DataSpace spaceToGet) +99
   System.Data.Entity.Core.Metadata.Edm.MetadataCache.LoadEdmItemCollection(MetadataArtifactLoader loader) +41
   System.Data.Entity.Core.Metadata.Edm.<>c__DisplayClass5.<GetMetadataWorkspace>b__0(String k) +37
   System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory) +72
   System.Data.Entity.Core.Metadata.Edm.MetadataCache.GetMetadataWorkspace(String cacheKey, MetadataArtifactLoader artifactLoader) +75
   System.Data.Entity.Core.Metadata.Edm.MetadataCache.GetMetadataWorkspace(DbConnectionOptions effectiveConnectionOptions) +126
   System.Data.Entity.Core.EntityClient.EntityConnection.GetMetadataWorkspace() +43
   System.Data.Entity.Core.Objects.ObjectContext.RetrieveMetadataWorkspaceFromConnection() +20
   System.Data.Entity.Core.Objects.ObjectContext..ctor(EntityConnection connection, Boolean isConnectionConstructor, ObjectQueryExecutionPlanFactory objectQueryExecutionPlanFactory, Translator translator, ColumnMapFactory columnMapFactory) +393
   System.Data.Entity.Core.Objects.ObjectContext..ctor(String connectionString, String defaultContainerName) +35
   App.Models.Entities..ctor() in C:\Users\Me\Desktop\App\App.MVC5\App.Entities.cs:37
   App.MVC5.Models.CurrentUser..ctor(Boolean IsGuiDetailsRequired) in C:\Users\Me\Desktop\App\App.MVC5\Models\AccountModels.cs:87
   App.MVC5.Controllers.HomeController..ctor() in C:\Users\Me\Desktop\App\App.MVC5\Controllers\HomeController.cs:11

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
   System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) +0
   System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +114
   System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +232
   System.Activator.CreateInstance(Type type, Boolean nonPublic) +83
   System.Activator.CreateInstance(Type type) +11
   System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +55

[InvalidOperationException: An error occurred when trying to create a controller of type 'App.MVC5.Controllers.HomeController'. Make sure that the controller has a parameterless public constructor.]
   System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +178
   System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType) +76
   System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName) +88
   Castle.Proxies.Invocations.IControllerFactory_CreateController.InvokeMethodOnTarget() +118
   Castle.DynamicProxy.AbstractInvocation.Proceed() +80
   Glimpse.Core.Extensibility.CastleInvocationToAlternateMethodContextAdapter.Proceed() +11
   Glimpse.Core.Extensions.AlternateMethodContextExtensions.TryProceedWithTimer(IAlternateMethodContext context, TimerResult& timerResult) +41
   Glimpse.Core.Extensibility.AlternateMethod.NewImplementation(IAlternateMethodContext context) +25
   Glimpse.Core.Extensibility.AlternateTypeToCastleInterceptorAdapter.Intercept(IInvocation invocation) +84
   Castle.DynamicProxy.AbstractInvocation.Proceed() +108
   Castle.Proxies.IControllerFactoryProxy.CreateController(RequestContext requestContext, String controllerName) +214
   System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory) +194
   System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) +50
   System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state) +48
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) +16
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +103
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
Community
  • 1
  • 1
Vinyl Warmth
  • 2,226
  • 3
  • 25
  • 50
  • 1
    Is the database local? Do you have the same version of SQL installed on both machines? – Chris Curtis Sep 15 '16 at 21:31
  • @ChrisCurtis thanks for your reply. Yes I am trying to run a local dev database. I have `SQL Server Developer` on the machine the apps runs on & `SQL Server Express` on the one it won't - am installing Developer on to this machine now & will report back.... – Vinyl Warmth Sep 16 '16 at 07:46
  • @ChrisCurtis I have installed `SQL Server Developer` but I'm getting the same error - any ideas? – Vinyl Warmth Sep 16 '16 at 08:02
  • 1
    My best guess is that despite the message about the metadata, it can't access the database. Make sure it exists and is accessible. – Chris Curtis Sep 16 '16 at 17:25
  • 1
    _"Please review the stack trace for more information"_ – CodeCaster Nov 25 '16 at 15:51
  • Added the stack trace to my post – Vinyl Warmth Nov 25 '16 at 16:04
  • 1
    Could it be that you have two different connection strings in your .settings files, one in your data project and one in your MVC project? The one in the MVC will be used at run time, the other one at design time. – Diana Nov 25 '16 at 22:24

1 Answers1

1

There's a very popular question over there and from its rating I can assume it helped a lot of people. It even mentions a blog post with complete troubleshooting for this problem. Also, this answer looks like something you didn't try yet.

Community
  • 1
  • 1
Codeguard
  • 7,787
  • 2
  • 38
  • 41