asp.net core 中 sql server 2017 数据库连接测试

使用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();
}

启动项目进行连接测试即可。

上一篇:,2,liunx命令格式


下一篇:【转】傅盛:怎样做一个创业公司CEO?