Why Doesn't The EntityConnection Object Contain the Login Password?

399 views Asked by At

I've got an app that uses EF CTP5.

In this particular situation, i need to degrade to some classic ADO.NET (in order to read multiple result sets in a stored procedure, which EF does not support).

As such, im trying to use the existing connection string from the EntityConnection object, like this:

var ctx = (this as IObjectContextAdapter).ObjectContext;
var efCon = ((EntityConnection) (ctx.Connection)).StoreConnection;
var con = new SqlConnection(efCon.ConnectionString);
con.Open(); // exception thrown

When i debug, i see that the ConnectionString does not contain the password, only the data source, username, database, etc.

Is this a security thing why they've removed it? Does EF hide the password somewhere and only use it when it executes stored procedures itself?

The EF connection string is not like classic ADO.NET connection strings, as it has metadata info.

So it looks like im going to have to strip out the part of the connection string that i need, put that in the web.config and pass it through to the Repository.

Surely there must be a better way!

1

There are 1 answers

1
Devart On BEST ANSWER

Try adding "Persist Security Info=True;" to the context connection string. This worked for me.