Entity framework with connection string via code

Asked

Viewed 412 times

2

I am developing an application, and I need the connection string to be set in the code itself, because there can be no app.config file..

1 answer

6


For this just pass your connection string in the constructor of its context.

For example:

public class MeuDbContext: DbContext
{
    public MeuDbContext(): base("Data Source=localhost;Initial Catalog=meudb;User Name=usuario;Password=senha;")
    {
       ......
       ......
    }
}

It is also possible to do the same by passing a DbConnection, by initializing it before passing it as parameter.

I hope I’ve helped!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.