Entity Framework getting an sql connection

后端 未结 8 1990
栀梦
栀梦 2021-02-08 02:16

In the light of Closing connections explicitly in Entity Framework and http://msdn.microsoft.com/en-us/library/bb738582%28v=vs.90%29.aspx it seems that I should be using the con

相关标签:
8条回答
  • 2021-02-08 02:47

    If the EF connection string is stored in your web config file, you can assign it to a SQL Data Source with this code:

                var connString = ConfigurationManager.ConnectionStrings["MyDataEntities"].ConnectionString;
                EntityConnection ec = new EntityConnection(connString);
                var storeConnect = ec.StoreConnection;
    
                SqlDataSource1.ConnectionString = storeConnect.ConnectionString;
    
    0 讨论(0)
  • 2021-02-08 02:49

    I believe the easiest way to create a SqlConnection in EF6 is to do the following:

    DBContext context = new DBContext();
    SqlConnection sqlconn = new SqlConnection(context.Database.Connection.ConnectionString);
    
    0 讨论(0)
提交回复
热议问题