How do I create connection string programmatically to MS SQL in Entity Framework 6?

c# entity-framework-6 sql-server wpf


In Entity Framework 6, how do I programmatically build a connection string to MS SQL?

I was hoping someone might provide some guidance or point me in the direction of a resource that demonstrates how to set up connection strings programmatically in EF 6. I'm using C# and WPF. Although the MSDN article states that you can use, it doesn't cover how to create connection strings specifically.

So, here is a functional EF6 example.


/entityFramework entityFramework codeConfigurationType="WPFwithEF.SqlConfiguration, WPFwithEF"


public class ProductContext : DbContext
    public ProductContext():base("Wpf")
    { }
    public DbSet<Category> Categories { get; set; }
    public DbSet<Product> Products { get; set; }


namespace WPFwithEF
public class SqlConfiguration : DbConfiguration

    public SqlConfiguration()
        SetDefaultConnectionFactory(new SqlConnectionFactory());

However, this configuration fails if the context base is "name=Wpf." Is there a method to make it work? And I'm seeking for the newest EF6 rather than the conventional approach.

2/12/2014 4:17:45 PM

Popular Answer

The can be used toEntityConnectionStringBuilder the following: How to create a connection string for an entity connection

2/12/2014 2:01:34 PM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow