keyword not supported data source

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-DEVSQLEXPRESS;Initial Catalog=ASPNETDB;Integrated Security=True;" 
     providerName="System.Data.EntityClient" />

Any ideas, what’s wrong?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

What you have is a valid ADO.NET connection string – but it’s NOT a valid Entity Framework connection string.

The EF connection string would look something like this:

<connectionStrings> 
  <add name="NorthwindEntities" connectionString=
     "metadata=.Northwind.csdl|.Northwind.ssdl|.Northwind.msl;
      provider=System.Data.SqlClient;
      provider connection string=&quot;Data Source=SERVERSQL2000;Initial Catalog=Northwind;Integrated Security=True;MultipleActiveResultSets=False&quot;" 
      providerName="System.Data.EntityClient" /> 
</connectionStrings>

You’re missing all the metadata= and providerName= elements in your EF connection string…… you basically only have what’s contained in the provider connection string part.

Using the EDMX designer should create a valid EF connection string for you, in your web.config or app.config.

Marc

UPDATE: OK, I understand what you’re trying to do: you need a second “ADO.NET” connection string just for ASP.NET user / membership database. Your string is OK, but the providerName is wrong – it would have to be “System.Data.SqlClient” – this connection doesn’t use ENtity Framework – don’t specify the “EntityClient” for it then!

<add name="ASPNETMembership" 
     connectionString="Data Source=MONTGOMERY-DEVSQLEXPRESS;Initial Catalog=ASPNETDB;Integrated Security=True;" 
     providerName="System.Data.SqlClient" />

If you specify providerName=System.Data.EntityClient ==> Entity Framework connection string (with the metadata= and everything).

If you need and specify providerName=System.Data.SqlClient ==> straight ADO.NET SQL Server connection string without all the EF additions

Method 2

This problem can occur when you reference your web.config (or app.config) connection strings by index…

var con = ConfigurationManager.ConnectionStrings[0].ConnectionString;

The zero based connection string is not always the one in your config file as it inherits others by default from further up the stack.

The recommended approaches are to access your connection by name…

var con = ConfigurationManager.ConnectionStrings["MyConnection"].ConnectionString;

or to clear the connnectionStrings element in your config file first…

<connectionStrings>
    <clear/>
    <add name="MyConnection" connectionString="...

Method 3

I was getting the same problem.
but this code works good try it.

<add name="MyCon" connectionString="Server=****;initial catalog=PortalDb;user id=**;password=**;MultipleActiveResultSets=True;" providerName="System.Data.SqlClient" />

Method 4

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.

Method 5

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
}

Method 6

I had this problem when I started using Entity Framework, it happened when I did not change the old SQL server connection to EntityFrameWork connection.

Solution:
in the file where connection is made through web.config file “add name=”Entities” connectionString=XYZ”,
make sure you are referring to the correct connection, in my case I had to do this

        public static string MyEntityFrameworkConnection
    {
        get
        {
             return ConfigurationManager.ConnectionStrings["Entities"].ConnectionString;
        }

    }

call MyEntityFrameworkConnection whenever connection need to be established.

private string strConnection= Library.DataAccessLayer.DBfile.AdoSomething.MyEntityFrameworkConnection;

note: the connection in web.config file will be generated automatically when adding Entity model to the solution.

Method 7

I know this is an old post but I got the same error recently so for what it’s worth, here’s another solution:

This is usually a connection string error, please check the format of your connection string, you can look up ‘entity framework connectionstring’ or follow the suggestions above.

However, in my case my connection string was fine and the error was caused by something completely different so I hope this helps someone:

  1. First I had an EDMX error: there was a new database table in the EDMX and the table did not exist in my database (funny thing is the error the error was not very obvious because it was not shown in my EDMX or output window, instead it was tucked away in visual studio in the ‘Error List’ window under the ‘Warnings’). I resolved this error by adding the missing table to my database. But, I was actually busy trying to add a stored procedure and still getting the ‘datasource’ error so see below how i resolved it:
  2. Stored procedure error: I was trying to add a stored procedure and everytime I added it via the EDMX design window I got a ‘datasource’ error. The solution was to add the stored procedure as blank (I kept the stored proc name and declaration but deleted the contents of the stored proc and replaced it with ‘select 1’ and retried adding it to the EDMX). It worked! Presumably EF didn’t like something inside my stored proc. Once I’d added the proc to EF I was then able to update the contents of the proc on my database to what I wanted it to be and it works, ‘datasource’ error resolved.

weirdness

Method 8

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"


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x