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

后端 未结 5 1705
一整个雨季
一整个雨季 2021-02-14 02:55

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

I\'m using c# and WPF and I was wondering if someone could show me how or link me to

5条回答
  •  醉酒成梦
    2021-02-14 03:17

    You could use the ProductivityTools.ConnectionString nuget package. It has 3 methods:

    • Creates connection string to server without database name
    • Creates connection string to server with the database name
    • Creates connection string for EntityFramework database context

    Last method will be right for you and asssuming that your edmx is named Product after invocation

    ConnectionStringHelper.ConnectionString.GetSqlEntityFrameworkConnectionString
    ("serverName", "databaseName", "Product");
    

    Package will return:

    metadata=res://*/Product.csdl|res://*/Product.ssdl| res://*/Product.msl; 
    provider=System.Data.SqlClient;provider connection string="Data Source=serverName;
    Initial Catalog=databaseName;Integrated Security=True"
    

提交回复
热议问题