The supplied connection is not valid because it contains insufficient mapping or metadata information

2,368 views
Skip to first unread message

Darin Truckenmiller (PM)

unread,
Feb 7, 2012, 12:09:39 PM2/7/12
to ninject
I searched google for the above error and only came back with one post
of off stack flow. (http://stackoverflow.com/questions/4073213/mvc3-
ef4-poco-repository-unitofwork-connection-error) The good news is
it's basically my exact setup. The bad news is their is no solution
for this problem. The gist of it is that when implementing DI with
EF, an error is thrown at runtime when attempting to access the
database and the error complains about the connection string being
incorrect. This is very unlikely because the string was autogenerated
by EF. I'll include the string and entire error as reference. This
string works fine when using it to model the DB so I'm not sure why
does not work at runtime.

metadata=res://*/Models.TeamTrack.csdl|res://*/Models.TeamTrack.ssdl|
res://*/Models.TeamTrack.msl;provider=System.Data.SqlClient;provider
connection string="data source=10.202.50.1;initial
catalog=TeamTrack;integrated
security=True;multipleactiveresultsets=True;App=EntityFramework"

System.ArgumentException was unhandled by user code
Message=The supplied connection is not valid because it contains
insufficient mapping or metadata information.
Parameter name: connection
Source=System.Data.Entity
ParamName=connection
StackTrace:
at System.Data.Objects.ObjectContext..ctor(EntityConnection
connection, Boolean isConnectionConstructor)
at System.Data.Objects.ObjectContext..ctor(EntityConnection
connection)
at DynamicInjectorad5446a29c914f2595cda202f2c20463(Object[] )
at
Ninject.Activation.Providers.StandardProvider.Create(IContext context)
in c:\Projects\Ninject\Maintenance2.2\ninject\src\Ninject\Activation
\Providers\StandardProvider.cs:line 82
at Ninject.Activation.Context.Resolve() in c:\Projects\Ninject
\Maintenance2.2\ninject\src\Ninject\Activation\Context.cs:line 157
at Ninject.KernelBase.<Resolve>b__7(IContext context) in c:
\Projects\Ninject\Maintenance2.2\ninject\src\Ninject
\KernelBase.cs:line 375
at
System.Linq.Enumerable.<>c__DisplayClass12`3.<CombineSelectors>b__11(TSource
x)
at
System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Linq.Enumerable.SingleOrDefault[TSource]
(IEnumerable`1 source)
at Ninject.Planning.Targets.Target`1.GetValue(Type service,
IContext parent) in c:\Projects\Ninject\Maintenance2.2\ninject\src
\Ninject\Planning\Targets\Target.cs:line 179
at Ninject.Planning.Targets.Target`1.ResolveWithin(IContext
parent) in c:\Projects\Ninject\Maintenance2.2\ninject\src\Ninject
\Planning\Targets\Target.cs:line 147
at
Ninject.Activation.Providers.StandardProvider.GetValue(IContext
context, ITarget target) in c:\Projects\Ninject\Maintenance2.2\ninject
\src\Ninject\Activation\Providers\StandardProvider.cs:line 97
at
Ninject.Activation.Providers.StandardProvider.<>c__DisplayClass2.<Create>b__1(ITarget
target) in c:\Projects\Ninject\Maintenance2.2\ninject\src\Ninject
\Activation\Providers\StandardProvider.cs:line 81
at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1
source)
at
Ninject.Activation.Providers.StandardProvider.Create(IContext context)
in c:\Projects\Ninject\Maintenance2.2\ninject\src\Ninject\Activation
\Providers\StandardProvider.cs:line 81
at Ninject.Activation.Context.Resolve() in c:\Projects\Ninject
\Maintenance2.2\ninject\src\Ninject\Activation\Context.cs:line 157
at Ninject.KernelBase.<Resolve>b__7(IContext context) in c:
\Projects\Ninject\Maintenance2.2\ninject\src\Ninject
\KernelBase.cs:line 375
at
System.Linq.Enumerable.<>c__DisplayClass12`3.<CombineSelectors>b__11(TSource
x)
at
System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Linq.Enumerable.SingleOrDefault[TSource]
(IEnumerable`1 source)
at Ninject.Planning.Targets.Target`1.GetValue(Type service,
IContext parent) in c:\Projects\Ninject\Maintenance2.2\ninject\src
\Ninject\Planning\Targets\Target.cs:line 179
at Ninject.Planning.Targets.Target`1.ResolveWithin(IContext
parent) in c:\Projects\Ninject\Maintenance2.2\ninject\src\Ninject
\Planning\Targets\Target.cs:line 147
at
Ninject.Activation.Providers.StandardProvider.GetValue(IContext
context, ITarget target) in c:\Projects\Ninject\Maintenance2.2\ninject
\src\Ninject\Activation\Providers\StandardProvider.cs:line 97
at
Ninject.Activation.Providers.StandardProvider.<>c__DisplayClass2.<Create>b__1(ITarget
target) in c:\Projects\Ninject\Maintenance2.2\ninject\src\Ninject
\Activation\Providers\StandardProvider.cs:line 81
at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1
source)
at
Ninject.Activation.Providers.StandardProvider.Create(IContext context)
in c:\Projects\Ninject\Maintenance2.2\ninject\src\Ninject\Activation
\Providers\StandardProvider.cs:line 81
at Ninject.Activation.Context.Resolve() in c:\Projects\Ninject
\Maintenance2.2\ninject\src\Ninject\Activation\Context.cs:line 157
at Ninject.KernelBase.<Resolve>b__7(IContext context) in c:
\Projects\Ninject\Maintenance2.2\ninject\src\Ninject
\KernelBase.cs:line 375
at
System.Linq.Enumerable.<>c__DisplayClass12`3.<CombineSelectors>b__11(TSource
x)
at
System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source)
at Ninject.ResolutionExtensions.Get(IResolutionRoot root, Type
service, IParameter[] parameters) in c:\Projects\Ninject
\Maintenance2.2\ninject\src\Ninject\Syntax
\ResolutionExtensions.cs:line 151
at
Web.NinjectControllerFactory.GetControllerInstance(RequestContext
requestContext, Type controllerType) in E:\My Documents\Visual Studio
2010\Projects\MVC3_Ops\Web\NinjectControllerFactory.cs:line 18
at
System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext
requestContext, String controllerName)
at System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase
httpContext, IController& controller, IControllerFactory& factory)
at
System.Web.Mvc.MvcHandler.<>c__DisplayClass6.<BeginProcessRequest>b__2()
at
System.Web.Mvc.SecurityUtil.<>c__DisplayClassb`1.<ProcessInApplicationTrust>b__a()
at
System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f)
at System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action
action)
at
System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust[TResult](Func`1
func)
at
System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase
httpContext, AsyncCallback callback, Object state)
at System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext
httpContext, AsyncCallback callback, Object state)
at
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext
context, AsyncCallback cb, Object extraData)
at
System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step,
Boolean& completedSynchronously)
InnerException:

Remo Gloor

unread,
Feb 8, 2012, 7:21:14 AM2/8/12
to nin...@googlegroups.com
Hi Darin

This is the wrong mailing list for this kind of problem.
It is an EF/Database problem and not related to Ninject. I think you will get much better answers at other places like stackoverflow.

Anyway I can remember having had this problem when moving between machines with different SQL Servers 2005/2008. I think I had to change the ProviderManifestToken to the appropriate value.

Remo

--
You received this message because you are subscribed to the Google Groups "ninject" group.
To post to this group, send email to nin...@googlegroups.com.
To unsubscribe from this group, send email to ninject+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/ninject?hl=en.

Darin Truckenmiller (PM)

unread,
Feb 8, 2012, 11:09:10 PM2/8/12
to ninject
Got it. I assumed it was a Ninject problem because Ninject threw the
error but it was unrelated.

KZ

unread,
Feb 13, 2012, 6:20:07 PM2/13/12
to ninject
I upgrade my web project to use Ninject 3.0.0-rc3 and did the required
changes for it. But I am now noticing that the web site is throwing an
exception ”The supplied connection is not valid because it contains
insufficient mapping or metadata information. Parameter name:
connection”

I was using Ninject.dll – Version 2.2.0.0 Ninject.Web.dll – Version
2.2.0.4. Do you know why it might be throwing this exception? It does
seem certain that it is caused by the Version 3.0 upgrade but I am not
able to find a resolution for it. Any idea?


On Feb 8, 10:09 pm, "Darin Truckenmiller (PM)"

Remo Gloor

unread,
Feb 14, 2012, 4:17:02 AM2/14/12
to nin...@googlegroups.com
This is thrown by the EF and non Ninject because of a misconfiguration of your DB connection. What have you tried so far? E.g.
- Have you tried changing the ProviderManifestToken in the edmx to the correct SQL server version?
- Have you tried recreating your edmx files from scratch?

-----Original Message-----
From: nin...@googlegroups.com [mailto:nin...@googlegroups.com] On Behalf Of KZ
Sent: Dienstag, 14. Februar 2012 00:20
To: ninject
Subject: [ninject] Re: The supplied connection is not valid because it contains insufficient mapping or metadata information

I upgrade my web project to use Ninject 3.0.0-rc3 and did the required changes for it. But I am now noticing that the web site is throwing an exception "The supplied connection is not valid because it contains insufficient mapping or metadata information. Parameter name:
connection"

I was using Ninject.dll - Version 2.2.0.0 Ninject.Web.dll - Version 2.2.0.4. Do you know why it might be throwing this exception? It does seem certain that it is caused by the Version 3.0 upgrade but I am not able to find a resolution for it. Any idea?

Kaustubh Zoal

unread,
Feb 14, 2012, 9:40:55 AM2/14/12
to nin...@googlegroups.com
I have not changed the database connection strings or re-created the edmx. I am not sure why would i need to do all that for upgrading to Ninject 3.0 when everything was working correctly while I was on Ninject Version 2.2.0.0. I was thinking that everything should work with just the required minor changes for the Version 3.0 upgrade. 
Do you think this can be related to .Net 4.0 FW?
I will try and recreate the edmx and see if that helps resolve this issue.

Thanks,
KZ

Remo Gloor

unread,
Feb 14, 2012, 10:05:05 AM2/14/12
to nin...@googlegroups.com

It seems I looked at the wrong change set

 

Try the following:

 

e.g. for

   public partial class MyEntities : ObjectContext

 

add the following binding

    this.Bind<MyEntities>().ToConstructor(x => new MyEntities());

Kaustubh Zoal

unread,
Feb 14, 2012, 10:31:40 AM2/14/12
to nin...@googlegroups.com
Hello Remo,

Where do you want I add this in the Designer.cs file?
My problem is that the error is thrown when it hits this constructor of one of my edmx's. It does not even go inside this constructor as it is doing the base call.

        /// <summary>
        /// Initialize a new SPOrdersEntities object.
        /// </summary>
        public SPOrdersEntities(EntityConnection connection) : base(connection, "SPOrdersEntities")
        {
            this.ContextOptions.LazyLoadingEnabled = true;
            OnContextCreated();
        }

Please let me know as I am not clear on where should I add the suggested binding?

Thanks,
KZ

Remo Gloor

unread,
Feb 14, 2012, 10:37:26 AM2/14/12
to nin...@googlegroups.com

Put it somewhere to your other Ninject bindings.

Kaustubh Zoal

unread,
Feb 14, 2012, 11:05:23 AM2/14/12
to nin...@googlegroups.com
Hello Remo,

So I have a class called StandardProcessWebPModule which is derived from Ninject.Web.WebModule. In this class I have the overridden Load in which all the context bindings are done.
As seen here, I have added the binding that you have suggested and still getting the exception System.ArgumentException: The supplied connection is not valid because it contains insufficient mapping or metadata information.
Note: This Load method is kept short but there are other bindings as well in it for other databases.

public override void Load()
    {
        // Contexts
        this.Bind<IKenticoCMSEntities>().ToConstructor(x => new KenticoCMSEntities());
        Bind<IKenticoCMSEntities>().To<KenticoCMSEntities>().InThreadScope().WithConstructorArgument("connectionString", ConfigurationManager.ConnectionStrings["KenticoCMSEntities"].ConnectionString);
    }
Please let me know if you need any more information. I am not sure but I hope this has got nothing to do with .Net FW 4.0 vs 4.5. I am using 4.0 in my web project.

Thanks,
KZ

Kaustubh Zoal

unread,
Feb 14, 2012, 11:16:29 AM2/14/12
to nin...@googlegroups.com
Here is the stack trace...hope it helps.

Source File: E:\Workspace\StandardProcess.CMS\StandardProcess.CMS.Data\Kentico.Designer.cs    Line: 77 

Stack Trace: 

[ArgumentException: The supplied connection is not valid because it contains insufficient mapping or metadata information.
Parameter name: connection]
   System.Data.Objects.ObjectContext..ctor(EntityConnection connection, Boolean isConnectionConstructor) +11656307
   System.Data.Objects.ObjectContext..ctor(EntityConnection connection, String defaultContainerName) +42
   StandardProcess.CMS.Data.KenticoCMSEntities..ctor(EntityConnection connection) in E:\Workspace\StandardProcess.CMS\StandardProcess.CMS.Data\Kentico.Designer.cs:77
   DynamicInjector7224076d529b46a7bde350ec48d5864a(Object[] ) +106
   Ninject.Activation.Context.Resolve() in c:\Projects\Ninject\ninject\src\Ninject\Activation\Context.cs:157
   System.Linq.WhereSelectEnumerableIterator`2.MoveNext() +238
   System.Linq.Enumerable.SingleOrDefault(IEnumerable`1 source) +299
   System.Linq.WhereSelectArrayIterator`2.MoveNext() +110
   System.Linq.Buffer`1..ctor(IEnumerable`1 source) +488
   System.Linq.Enumerable.ToArray(IEnumerable`1 source) +104
   Ninject.Activation.Providers.StandardProvider.Create(IContext context) in c:\Projects\Ninject\ninject\src\Ninject\Activation\Providers\StandardProvider.cs:96
   Ninject.Activation.Context.Resolve() in c:\Projects\Ninject\ninject\src\Ninject\Activation\Context.cs:157
   System.Linq.WhereSelectEnumerableIterator`2.MoveNext() +238
   System.Linq.Enumerable.SingleOrDefault(IEnumerable`1 source) +299
   Ninject.Activation.Strategies.PropertyInjectionStrategy.Activate(IContext context, InstanceReference reference) in c:\Projects\Ninject\ninject\src\Ninject\Activation\Strategies\PropertyInjectionStrategy.cs:73
   Ninject.Infrastructure.Language.ExtensionsForIEnumerableOfT.Map(IEnumerable`1 series, Action`1 action) in c:\Projects\Ninject\ninject\src\Ninject\Infrastructure\Language\ExtensionsForIEnumerableOfT.cs:32
   Ninject.Web.NinjectHttpModule.OnPreRequestHandlerExecute(Object sender, EventArgs e) in c:\Projects\Ninject\ninject.web\src\Ninject.Web\NinjectHttpModule.cs:108
   System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +80
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +270

Remo Gloor

unread,
Feb 14, 2012, 11:26:50 AM2/14/12
to nin...@googlegroups.com

Sorry I can’t help you on this without knowing your code.

Just setup your bindings in some way that the correct constructor of your Entities is called. Read for more information about constructor selection

 

http://www.planetgeek.ch/2011/05/28/ninject-constructor-selection-preview/

http://www.planetgeek.ch/2011/12/30/new-features-and-changes-of-ninject-3-0/

Kaustubh Zoal

unread,
Feb 14, 2012, 9:09:56 PM2/14/12
to nin...@googlegroups.com
Hello Remo,

This is the way I have done the mapping using Version 2.2.0.0 of Ninject 
Bind<IMyEntities>().To<MyEntities>().InRequestScope().WithConstructorArgument("connectionString", ConfigurationManager.ConnectionStrings["MyEntities"].ConnectionString);  

After upgrading to 3.0 I changed it to use either of them   
Bind<IMyEntities>().ToConstructor(x => new MyEntities()); 
or 
Bind<IMyEntities>().ToConstructor(x => new MyEntities(ConfigurationManager.ConnectionStrings["MyEntities"].ConnectionString)); 
or 
Bind<IMyEntities>().ToConstructor(x => new MyEntities(new EntityConnection (ConfigurationManager.ConnectionStrings["MyEntities"].ConnectionString)));  

After trying all the above mentioned 3 different ways I am still getting the error. Everytime the 3rd constructor is getting called somehow.  
I am not sure what else to try. I have kind of invested a very good amount of time trying different things and still not coming to a conclusion/resolution. 
If I am not able to find/resolve this problem somehow I will have to remove all the Ninjet references all togetther and go for some other DI's.                                                      
I am not sure how can I get the code to you but please let me know if you would like to do that also, maybe I can set up something.

Thanks,
KZ

StriplingWarrior

unread,
Jun 25, 2012, 3:39:06 PM6/25/12
to nin...@googlegroups.com
I had the same issue and it turned out to be related to using NinjectWebCommon.cs. Switching back to using NinjectHttpApplication seems to have fixed it. I describe this in more detail at http://stackoverflow.com/a/11194858/120955.

Cheers,

James
Reply all
Reply to author
Forward
0 new messages