 |
|
ปรึกษาเรื่องการเชื่อมต้อ MySQL ของ .net core หน่อยค่ะ |
|
 |
|
|
 |
 |
|
Google
--- dapper mysql .net core
--- dapper maria .net core
ได้ยินมาตั้งนานแล้ว แต่ผมไม่เคยใช้
--- ผมว่ามันใช้ได้เลยนะ (อาจต้องปรับปรุงอีกนิดหน่อย ให้เข้ากับสไตล์ของผม/คุณ)
ผมงมเข็มกลางมหาสมุทร ลำพัง คนเดียวโดดฯ ไร้ซึ่งครูบาอาจารย์ กว่าจะเอามันลงได้
--- .Net Core 2.2 And Agular (ต่อให้เป็น .Net Core 2.2 --> 10 หรือมากกว่านั้นตรูก็บ่ยั่นแล้ว)
ปิดเกม .NET CORE & Angular บนระบบงานจริง (ทำแล้วได้เงิน)
เมื่อก่อนเคยเขียนแบบนี้ แต่ตอนนี้คงไม่จำเป็นแล้ว
Code (JavaScript)
$(document).ready(function() {
$("#mainPage").html("Loading...");
var pagelink = "pages/about/";
var url = pagelink + "index.html";
$.ajax({
url : url,
type : "GET",
dataType : "html"
}).done(function(data) {
$("#mainPage").html(data);
$("#mainPage link").each(function() {
var cssLink = pagelink + $(this).attr('href');
$("head").append("<link rel='stylesheet' href='" + cssLink + "' />")
});
$("#mainPage script").each(function() {
var jsLink = pagelink + $(this).attr('src');
$("head").append("<script src='" + jsLink + "' ></script>")
});
}).fail(function(jqXHR, textStatus, errorThrown) {
$("#mainPage").html("Error!! File is not loaded");
});
});


|
 |
 |
 |
 |
Date :
2019-03-26 21:13:12 |
By :
หน้าฮี |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
.NET Core 2.2 appsettings.json
Code (XML)
{
"ConnectionStrings": {
"DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=aspnet-ERPWeb-AD458691-B814-4CD5-9D70-6BC8BC95540E;Trusted_Connection=True;MultipleActiveResultSets=true"
},
"Logging": {
"LogLevel": {
"Default": "Warning"
}
},
"AllowedHosts": "*",
"DatabaseSettings": {
"RDBMSType": "Oracle",
"RDBMSName": "DemoDB",
"RDBMSConnectionString": "Server=อะไรก็ว่ากันไป; UserName=;Password=; ABC+"
}
}
File Startup.cs
Code (C#)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.UI;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using ERPWeb.Data;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System.IO;
namespace ERPWeb
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
var testVar0 = configuration.GetSection("DatabaseSettings")["RDBMSType"];
var testVar1 = configuration.GetSection("DatabaseSettings")["RDBMSName"];
var testVar2 = configuration.GetSection("DatabaseSettings")["RDBMSConnectionString"];
//จะทำอะไรก็ว่ากันไป
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.Configure<CookiePolicyOptions>(options =>
{
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.None;
});
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(
Configuration.GetConnectionString("DefaultConnection")));
services.AddDefaultIdentity<IdentityUser>()
.AddDefaultUI(UIFramework.Bootstrap4)
.AddEntityFrameworkStores<ApplicationDbContext>();
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseDatabaseErrorPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
//app.UseCookiePolicy();
//app.UseAuthentication();
//app.UseMvc(routes =>
//{
// routes.MapRoute(
// name: "default",
// template: "{controller=Home}/{action=Index}/{id?}");
//});
}
}
}
|
 |
 |
 |
 |
Date :
2019-03-26 21:39:01 |
By :
หน้าฮี |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|