使用sql server 2017 進行鏈接:sql
配置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"
}
}
}json
在 startup.cs 中添加數據庫服務app
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(); }
啓動項目進行鏈接測試便可。ide