Get SqlConnection from DbConnection
Well, if both can share the same Connection String
then I guess they're both SqlConnection
.
Try this instead:
var connection = rep.Database.Connection as SqlConnection;
One of the possible ways to work this around would be to add Persist Security Info=true
to your connection string.
I had a similar problem with ProfiledConnection (HibernatingRhinos.Profiler.Appender.ProfiledDataAccess.ProfiledConnection)
and what I needed was SqlConnection, this did the trick:
ProfiledConnection profiledConnection = dbContext.Database.Connection as ProfiledConnection;SqlConnection sqlConnection = (SqlConnection)profiledConnection.Inner;