Extract connection string from an Entity Connection String

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

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



        
5条回答
  •  借酒劲吻你
    2021-02-05 10:19

    While Jan Remunda rightly points out that you don't need to create a context, and while his solution is useful if you want to create a connection explicitly right after reading the EntityClient connection string, it's still a little convoluted if all you want is to retrieve the inner-provider connection string (which is what OP asks).

    It's true that you don't have to open the connection, you can just retrieve the ConnectionString of the inner StoreConnection then discard it right after, but why?

    Use the appropriate connection string builder instead:

    new EntityConnectionStringBuilder(outerConnectionString).ProviderConnectionString
    

    See EntityConnectionStringBuilder.

提交回复
热议问题