简体   繁体   中英

Error trying to connect to SQL Server database

I am trying to generate a connection to the database in ASP.NET Core MVC, but when trying to enter the index page of my miles controller, it generates an error, because the connection to the database has not been made.

This is my appsettings.json :

"ConnectionStrings": {
    "MillaContext": "Server=server;Database=Bit_V2;User Id=sa; Password=password;Trusted_Connection=True;MultipleActiveResultSets=true"
}

This is my startup.cs:

public void ConfigureServices(IServiceCollection services)
{
    ...

    services.AddDbContext<MillaContext>(options =>
                options.UseSqlServer(Configuration.GetConnectionString("MillaContext")));
    services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
}

And this is error:

在此处输入图像描述

Since you are using sql server, your connection string should be like this:

"MillaContext": "Data Source=server;Initial Catalog=Bit_V2;Integrated Security=False;
User ID=sa;Password=password;"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM