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))
// ));
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/38371.html
標籤:.NET Core
上一篇:.NETCore在解構式(Finalize)在Linux下引起程式例外退出現象
下一篇:[Asp.Net Core] Blazor Server Side 擴展用途 - 配合CEF來制作帶瀏覽器核心的客戶端軟體
