使用sql server 2017 进行连接:
配置appsettings.json文件
{
"ConnectionStrings": {
"DefaultConnection": "Data Source=DESKTOP-9MR9DST;Initial Catalog=Test;Persist Security Info=False;User ID=sa;pwd='000000';Pooling=False;MultipleActiveResultSets=False;Encrypt=False;TrustServerCertificate=True"
},
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Warning"
}
}
}
在 startup.cs 中添加数据库服务
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders(); // Add application services.
services.AddTransient<IEmailSender, EmailSender>(); services.AddMvc();
}
启动项目进行连接测试即可。