locked
Connection String Error RRS feed

  • Question

  • User-1177023326 posted

    Hello

    Am using Entity Framework for application. the problem is that I am using Entity Framework to perform action with my database , which is working fine. but for some other reason i  need to perform other purpose using Sql Connection to Store and Retrieve  data from database. but getting error keyword not supported 'metadata'

    My connection string is

      <add name="AutoDBEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=LAPTOPxxxxxx;initial catalog=AutoDB;user id=sa;password=xccccc;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

    Please i will appreciate if this could be solved out.
    Thank you
    Friday, December 30, 2016 12:56 PM

Answers

  • User-691209617 posted

    add your connection string like this

      <connectionStrings>
        <add name="myconnectionstring"  connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=LAPTOPxxxxxx;initial catalog=AutoDB;user id=sa;password=xccccc;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
      </connectionStrings>
    
    

    and in Context use it like this

            public YourEntityName()
                : base("name=myconnectionstring")
            {
            }
        

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, December 30, 2016 1:11 PM
  • User-1177023326 posted
     public YourEntityName()
                : base("name=myconnectionstring")
            {
            }

    Please can you give better explanation and sample on this.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, December 30, 2016 2:26 PM
  • User753101303 posted

    Hi,

    My understanding is that you are trying to use an EF connexion string with SqlClient. If yes, for SQL Client only the part that starts at "Data Source=" is relevant. What is shown before is for EF connection strings (which is basically EF info + a SQL Server connection string added as a "provider connection string")

    Another option is to use the Database property that exposes the underlying connection so that you can fall back to plain SQL even when using primilarly an EF context.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, December 30, 2016 3:38 PM
  • User-1177023326 posted

    Thank You Patric  

    Can you help to check this if its a perfect method to use

    private static string RemoveEntityFrameworkMetadata(string efConnection)
          {
             
     
     
              string entityConnectionString = efConnection; //System.Configuration.ConfigurationManager.ConnectionStrings["EFcONNECTIONSTRING"].ConnectionString;
     
              var builder = new EntityConnectionStringBuilder(entityConnectionString);
              string providerConnectionString = builder.ProviderConnectionString;
              return providerConnectionString;

    }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, January 1, 2017 1:38 PM

All replies

  • User-691209617 posted

    add your connection string like this

      <connectionStrings>
        <add name="myconnectionstring"  connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=LAPTOPxxxxxx;initial catalog=AutoDB;user id=sa;password=xccccc;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
      </connectionStrings>
    
    

    and in Context use it like this

            public YourEntityName()
                : base("name=myconnectionstring")
            {
            }
        

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, December 30, 2016 1:11 PM
  • User-1177023326 posted
     public YourEntityName()
                : base("name=myconnectionstring")
            {
            }

    Please can you give better explanation and sample on this.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, December 30, 2016 2:26 PM
  • User753101303 posted

    Hi,

    My understanding is that you are trying to use an EF connexion string with SqlClient. If yes, for SQL Client only the part that starts at "Data Source=" is relevant. What is shown before is for EF connection strings (which is basically EF info + a SQL Server connection string added as a "provider connection string")

    Another option is to use the Database property that exposes the underlying connection so that you can fall back to plain SQL even when using primilarly an EF context.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, December 30, 2016 3:38 PM
  • User-1177023326 posted

    Thank You Patric  

    Can you help to check this if its a perfect method to use

    private static string RemoveEntityFrameworkMetadata(string efConnection)
          {
             
     
     
              string entityConnectionString = efConnection; //System.Configuration.ConfigurationManager.ConnectionStrings["EFcONNECTIONSTRING"].ConnectionString;
     
              var builder = new EntityConnectionStringBuilder(entityConnectionString);
              string providerConnectionString = builder.ProviderConnectionString;
              return providerConnectionString;

    }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, January 1, 2017 1:38 PM