asp.net core 中 sql server 2017 數據庫鏈接測試

使用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

相關文章
相關標籤/搜索