Extract connection string from an Entity Connection String

前端 未结 5 626
没有蜡笔的小新
没有蜡笔的小新 2021-02-05 09:50

When creating and ADO.NET Entity Connection String you get something like



        
5条回答
  •  悲哀的现实
    2021-02-05 10:15

    You don't need to create instance of ObjectContext. Because in that case you must reference assemblies where metadata are stored and for performance is not also very good.

    There is simpler way to get provider connection string in StoreConnection property.

     using (var ec = new EntityConnection(connstr.ConnectionString))
     {
       var sqlConn = ec.StoreConnection as SqlConnection;
       sqlConn.Open();
     }
    

提交回复
热议问题