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

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

 

posted @ 2018-02-12 12:54  小笨0104  阅读(2533)  评论(0编辑  收藏  举报