当前位置: 移动技术网 > IT编程>开发语言>.net > netcore数据连接配置

netcore数据连接配置

2020年04月29日  | 移动技术网IT编程  | 我要评论

戴维民,乐邦卡盟,校园新闻联播

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))
            //     ));

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网