Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keyword not supported: 'metadata'.? with Sql Connection in Entityt Framework with MVC3

I am using Entity Framework 4 with my Asp.Net MVC3 application. My problem is that I am using Entity Framework to perform action with my database , That is working fine. For some other purpose I am also using Sql Connection to Store and Retrieve my data from database. I am getting

[Keyword not supported: 'metadata']

error while connecting with my database.

This is my web config

  <add name="VibrantEntities" connectionString="metadata=res://*/Vibrant.csdl|res://*/Vibrant.ssdl|res://*/Vibrant.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=KAPS-PC\KAPSSERVER;initial catalog=vibrant;integrated security=True;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

I am using class Library, So this is my App Config.

   <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.3.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />

   <add name="VibrantEntities" connectionString="metadata=res://*/Vibrant.csdl|res://*/Vibrant.ssdl|res://*/Vibrant.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=KAPS-PC\KAPSSERVER;initial catalog=vibrant;integrated security=True;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
like image 751
Kaps Hasija Avatar asked Oct 18 '12 02:10

Kaps Hasija


2 Answers

The connection string for ADO.NET (in this case SqlConnection) doesn't take that format. You're using the one specific for Entity Framework. The ADO.NET one should be something like:

"data source=KAPS-PC\KAPSSERVER;initial catalog=vibrant;integrated security=True"

So, to sum it up, you need two separate connection strings, one for EF and one for ADO.NET

like image 127
psousa Avatar answered Sep 23 '22 23:09

psousa


You connection string is specific to Entity Framework and contains metadata. You need to get your provider connection string from it. You can do it using EntityConnectionStringBuilder:

var efConnectionString = "Your Entity Framework connection string";
var builder = new EntityConnectionStringBuilder(efConnectionString);
var regularConnectionString = builder.ProviderConnectionString;
like image 32
Nikolai Samteladze Avatar answered Sep 22 '22 23:09

Nikolai Samteladze