keyword not supported data source

Viewed 158294

I have an asp.net-mvc application with the default membership database. I am accessing it by ADO.NET Entity Framework.

Now I want to move it to IIS, but several problems showed up. I had to install SQL Server Management Studio, Create new DB, import there all the data from the previous .MDF file. Only thing left to do (as far a I know) is to change to connection string. However, I am not really experienced with this and keep getting the Keyword not supported: 'data source'. exception. Here is my connection string:

<add name="ASPNETDBEntities" 
     connectionString="Data Source=MONTGOMERY-DEV\SQLEXPRESS;Initial Catalog=ASPNETDB;Integrated Security=True;" 
     providerName="System.Data.EntityClient" />

Any ideas, what's wrong?

8 Answers

I was getting the same error, then updated my connection string as below,

<add name="EmployeeContext" connectionString="data source=*****;initial catalog=EmployeeDB;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework" providerName="System.Data.SqlClient" />

Try this it will solve your issue.

If you supplying the connection string directly to entity framework, remember to change the two XML escape code &quot; characters into actual quote symbols in the provided string, otherwise this same error can occur.

I am overriding the connection string using a separate partial class file to the generated one that passed the EF connection string to its base class.

    // Partial class to use instead of generated version
    public partial class PartEntities : DbContext
    {
        // Use the full EF6 connection string as described in other comments here
        // Note: This is only here for testing, will be keeping outside source code
        const string fullEFconnectionString = "metadata= ...";

        // Extra parameter differentiates constructor
        public PartEntities(bool b)
            : base(fullEFconnectionString.Replace("&quot;", "\""))
        {
        }
    }

So wherever in the code I want to access the database context I do this -

using (var ctx = new PartEntities(true))
{
    // Code that uses the context goes here
}

In case it helps others, also please check the providerName in the connection string. Depending on how the EF Context is coded, you may need SqlClient instead of EntityClient

providerName="System.Data.EntityClient"
Related