How to get the model model connection string?

Given this object model variable:

DataBaseEntities db = new DataBaseEntities ();

The following code cannot be used from the db varibale connection string

SqlBulkCopy sbc = new SqlBulkCopy(db.Connection.ConnectionString);
+5
source share
2 answers

try with this approach:

private string GetADOConnectionString()
{
    var db = new DataBaseEntities();

    EntityConnection ec = (EntityConnection)db.Connection;

    return ec.StoreConnection.ConnectionString;
}

I found this here: Getting SqlConnection from EntityConnection

also see here: EntityConnection.StoreConnection Property

Edit: of course, this should be adapted, and you should check for zeros or check before casting ... this is just an example; -)

+5
source
Dim objEntities As New DBEntities

I have a connection string already installed in the .edmx file in my project.

-2
source

All Articles