首页 > Web开发 > 详细

netcore数据连接配置

时间:2020-04-28 18:19:15      阅读:58      评论:0      收藏:0      [点我收藏+]

netcore数据连接配置

第一种

appsettings.json

{

  "ConnectionStrings": {
    "DefaultConnection": "Server=localhost;database=typecho;uid=root;pwd=woshishui;"
  },
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Information"
    }
  },
  "AllowedHosts": "*"
}

ConfigureServices

? services.AddDbContext<typechoContext>(options=>options.UseMySql(Configuration.GetConnectionString("DefaultConnection")));


第二种

ConfigureServices

      // other service configurations go here
            // replace "YourDbContext" with the class name of your DbContext
services.AddDbContextPool<typechoContext>(options => options
            //     // replace with your connection string          .UseMySql("Server=localhost;Database=typecho;User=root;Password=woshishui;", mySqlOptions => mySqlOptions
            //         // replace with your Server Version and Type
    .ServerVersion(new ServerVersion(new Version(8, 0, 19), ServerType.MySql))
            //     ));

netcore数据连接配置

原文:https://www.cnblogs.com/ouyangkai/p/12795695.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!