DDD + Entityframework + Migrations + SQL Server

Asked

Viewed 216 times

1

Hello, I have a Solution that I am implementing the DDD architecture with Entityframework, Migrations and SQL Server! However I am not able to connect to my local database when performing the command of Migrations: 'Updata-database'! I believe that only with Connectionstring inserted in the API Webconfig can I make this connection. Is that right? or I have to make another configuration in the DDD?

Currently my Connectionstring is as follows:

 <connectionStrings>
    <add name="BWSDatabase" 
         connectionString="Server=localhost; 
                           Database=BWSDatabase; 
                           Data Source=DESKTOP-PTI280V;
                           Integrated Security=True;
                           Connect Timeout=30;
                           Encrypt=False;
                           TrustServerCertificate=False;
                           ApplicationIntent=ReadWrite;
                           MultiSubnetFailover=False" 
         providerName="System.Data.SqlClient" />
  </connectionStrings>

This way the tables are generated locally in a SLQ Server express booth in SQL Server Object Explorer, as well as the photo below...

inserir a descrição da imagem aqui

I’m using the layer DDD, which are: 1-Services (API Layer) 2- Application (Development Layer) 3- Domain 4- Below (Layer where Migrations is located)

I am running the command from 'Package Manager Console', and only the tables are generated, and if you run again the command displays the message that there is no update in Migrations

Thank you in advance.

  • Are you doing multilayered development? If so, you have how to add to the question the layers you are using and where is the layer where the layers are migrations?. You executed the command by package manager console?, if yes, you can add the question to stack generated?

  • I’m sorry, I didn’t understand one thing, on top you say you can’t generate the bank, on the bottom you say the tables are generated, the problem is not clear :X

  • The problem is that tables are generated in the localDb SQL Server Express and not in the SQL Server database itself

1 answer

1


The connection string may be simpler than this, of course, depending on what you want, it is still worth passing some definitions through it. But there must be a reason.

Assuming you’ve created an instance of SQLEXPRESS you can use the authentication of windows to connect to the database, your string would look like this:

<add name="MeuSistemaDbContext" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=BANCO_DE_DADOS;Integrated Security=true providerName="System.Data.SqlClient" />

A fact that may also be occurring in your case is that your context does not call the connection string, by default it will look for the connection string that has the same name, ie if your context calls MeuSistemaDbContext, he will look for the string de conexão with that name. If it has a different name you should pass that name to the constructor in your DbContext

Now, if you have 1 user and password to access the base, you can use the following string de conexão

<add name="MeuSistemaDbContext" connectionString="Database=BANCO_DE_DADOS; Server=.\SQLEXPRESS; User Id=USUARIO; Password=SENHA" providerName="System.Data.SqlClient" />

Browser other questions tagged

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