netcore数据连接配置

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(options=>options.UseMySql(Configuration.GetConnectionString("DefaultConnection")));


第二种

ConfigureServices

      // other service configurations go here
            // replace "YourDbContext" with the class name of your DbContext
services.AddDbContextPool(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数据连接配置)