EMAI
EMAI

Reputation: 744

How to fetch entity model connection string?

Given this entity model variable:

DataBaseEntities db = new DataBaseEntities ();

The below code can not use from db varibale connection string

SqlBulkCopy sbc = new SqlBulkCopy(db.Connection.ConnectionString);

Upvotes: 5

Views: 894

Answers (2)

Davide Piras
Davide Piras

Reputation: 44605

try with this approach:

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

    EntityConnection ec = (EntityConnection)db.Connection;

    return ec.StoreConnection.ConnectionString;
}

I've 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 nulls or check before casting... it's just an example ;-)

Upvotes: 5

jdross
jdross

Reputation: 1206

Dim objEntities As New DBEntities

I have the connection string already set within .edmx file in my project.

Upvotes: -2

Related Questions