mvc application with visual studio code, Connection Strings

Asked

Viewed 137 times

0

I am using Visual Studio Code with the extension mssql on linux and need to get the Connection String from a database I’ve already created, but I’m not getting.

The teacher of the course that I am doing is using the visual studio and did as follows:

propiedas

After he copies this excerpt he uses here:

inserir a descrição da imagem aqui

I just need to get this text from Connection Strings for my code to work.

  • Welcome Eduardo Carvalho. Instead of images, try to post code snippets. If possible also show where you want to start your context.

1 answer

1

As you did not specify in the question, it follows the way you could do in the Startup.Cs:

public class Startup
{
    public Startup(IConfiguration configuration)
    {
        Configuration = configuration;
    }

    public IConfiguration Configuration { get; }


    public void ConfigureServices(IServiceCollection services)
    {
        //...

        services.AddDbContext<ApplicationDbContext>(options =>
            {
                options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"));
            });

        //Restante do método Configuration abaixo......
    }

    //Restante da classe Startup abaixo......
    //.........
    //.........
}

See a full example here.

Microsoft documentation on connection strings.

  • This image code also generates the database tables. That’s why I think it has to be this way.

  • @Eduardocarvalho is the EF that generates the tables in the BD. In the images of your question you only have a screen of properties that I could not recognize due to the quality of it and a json configuration file.

Browser other questions tagged

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