Jorge
Jorge

Reputation: 18257

adding overload to DBContext

I'm trying to add the password to my string connection in the constructor of my DBContext like this

public partial class Control : DbContext
{
    public Control(string conexion): base(crearConexion(conexion))
    {

    }

    public static String crearConexion(string nombreConexion) 
    {
        string conexion = ConfigurationManager.ConnectionStrings[nombreConexion].ConnectionString;
        SqlConnectionStringBuilder sqlBuilder = new SqlConnectionStringBuilder(conexion);
        sqlBuilder.Password = "somepassword";
        return sqlBuilder.ToString();
    }
}

But It throws this exception system.argumentexception keyword not supported 'metadata'

Why am I doing wrong??

Upvotes: 2

Views: 856

Answers (1)

Jeff Ogata
Jeff Ogata

Reputation: 57803

Try using the EntityConnectionStringBuilder.

If you look at an EF connection string (check your app.config file), you'll see the sql server connection string is part of it, but also that there is additional information, which the SqlConnectionStringBuilder can't parse:

metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=localhost;initial catalog=Test;integrated security=True;multipleactiveresultsets=True;App=EntityFramework"

Upvotes: 4

Related Questions