DbContext constructor connection string error keyword name not supported

connection-string entity-framework-6

Question

The entity framework documentation states that I can use a named parameter when supplying my connection string:

public class BloggingContext : DbContext 
{ 
    public BloggingContext() 
        : base("name=BloggingCompactDatabase") 
    { 
    } 
}

I normally don't normally bother with the named parameter:

public TspDbContext()
    : base("ViktorVooey") { }

but I thought I'd give it a go just for confirmation:

   public TspDbContext()
            : base("name=ViktorVooey") { }

and it fails saying

Keyword not supported : name

This is on EF6. So I'm sort of stuck between not really caring but still wanting to know "what's up with that" all the same.

1
1
6/9/2014 3:07:04 AM

Popular Answer

I came across your post because I had the same error. The MSDN documentation for EF 6 DbContext explicitly states that the 'name=' part of the constructor string parameter is supported and means:

The name can also be passed in the form 'name=myname', in which case the name must be found in the config file or an exception will be thrown.

In other words the "name=" prefix forces EF to only look for a config file entry for the connection string.

So you should check that the value you pass with "name=" is actually a name key value in your config file.

For example, in the config file:

<add name="MyContextName" connectionString="blah blah"/>

In the constructor:

public MyContext()
            : base("name=MyContextName")
2
7/9/2018 12:15:56 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow