Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Any ideas, what's wrong?

like image 452
Trimack Avatar asked Sep 10 '09 09:09

Trimack


2 Answers

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=SERVER\SQL2000;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-DEV\SQLEXPRESS;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

like image 180
marc_s Avatar answered Sep 19 '22 08:09

marc_s


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="... 
like image 23
Baldy Avatar answered Sep 19 '22 08:09

Baldy