Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6385003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:50:42+00:00 2026-05-25T02:50:42+00:00

I have many DBs in one SQL server. I placed connectionString as template(look at

  • 0

I have many DBs in one SQL server.
I placed connectionString as template(look at Initial Catalog={0}) into web.config.

<add name="ent" connectionString="metadata=res://*/ent.csdl|res://*/ent.ssdl|res://*/ent.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=1.1.1.1;Initial Catalog={0};Persist Security Info=True;User ID=user;Password=pass;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />

I want to create the objectContext with correct connectionString. I thought to do the following, CreatObjectContext<SiteEntities>('MySite') but I get error Unable to determine the provider name for connection of type 'System.Data.EntityClient.EntityConnection'.

public T CreatObjectContext<T>(string dbName) where T : ObjectContext, new()
{          
       var conStr = ConfigurationManager.ConnectionStrings["ent"].ConnectionString;
       var entityBuilder = new EntityConnectionStringBuilder(conStr);
       entityBuilder.Provider = "System.Data.SqlClient";
       // Build correct conString to the db
       entityBuilder.ProviderConnectionString = string.Format(entityBuilder.ProviderConnectionString, dbName);

       var connection = new EntityConnection(entityBuilder.ConnectionString);                          
       var builder = new ContextBuilder<T>();

       return builder.Create(connection);           
}

What I’m doing wrong? How I can create the context?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T02:50:43+00:00Added an answer on May 25, 2026 at 2:50 am

    If you are using EntityConnectionStringBuilder, you only need to store the sqlserver connection strings in your web.config. EntityConnectionStringBuilder can then convert those to EF4 connection strings.

    Example web.config

        <connectionStrings>
          <add name="db1" connectionString="data source=localhost\SQLEXPRESS;initial catalog=db1;integrated security=True;multipleactiveresultsets=True;App=EntityFramework" /> 
          <add name="db2" connectionString="data source=localhost\SQLEXPRESS;initial catalog=db2;integrated security=True;multipleactiveresultsets=True;App=EntityFramework" />
        </connectionStrings>
    

    And we can change your method to something like:

    public ObjectContext CreatObjectContext(string dbName)
    {          
           var conStr = ConfigurationManager.ConnectionStrings[dbName].ConnectionString;
           var entityBuilder = new EntityConnectionStringBuilder();
    
           entityBuilder.Provider = "System.Data.SqlClient";
           entityBuilder.ProviderConnectionString = conStr;
    
           entityBuilder.MetaData = @"res://*/ent.csdl|res://*/ent.ssdl|res://*/ent.msl";
    
           return new ObjectContext(entityBuilder.ToString());          
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a DB (in SQL Server 2008 SP3) include many tables and each
ok, say you have two dbs. one you use as a master template which
I have many small files containing code fragments, pseudo-code algorithms, classes, templates, SQL-samples, etc.,
I have many aspx page includes in my web form. I want to convert
I have many .sql files with lots of empty lines, for example, WITH cteTotalSales
I have many SWF file those I have included in my web page using
I have many security accounts on the sql database and i want to remove/add
My SQL Server 2008 has one central database that has some global functions, e.g.
I have many lines like this in a sql file VALUES (12654, 'somestuff', 'some
I have many small java programs running in crons in my server. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.