 |
|
VB.NET โปรแกรมแจ้งเตือนว่า OleDbException: Multiple-step OLE DB operation generated errors. ค่ะ |
|
 |
|
|
 |
 |
|
ผมใช้ VS 2019 Community Version 16.4.0
--- ผม migrate .NET Core 2.2 VB/C# ทำงานได้ดีไม่มีปัญหา ---> ขึ้นมา .NET Core 3.1 และทิ้ง VB เอาไว้ข้างหลัง
ปัญหาตามมาเพียบเลย อทิเช่น
--- Web API Method Post ผมไม่สามารถใช้ JObject ได้
Code (C#)
[AllowAnonymous]
[HttpPost]
[Route("SignIn")]
public IActionResult SignIn(JObject user)
{
//res = response, var <> dynamic
//var resMessage = new { Id = 1, errorMessage = "" };
dynamic resMessage = new { Id = 1, errorMessage = string.Empty };
//if (string.IsNullOrEmpty((user.Value<string>("username") ?? null)))
//{
// resMessage.errorMessage = "User Name Required";
//}
//else if (string.IsNullOrEmpty((user.Value<string>("password") ?? null)))
//{
// //All when you needs.
//}
//All when you needs.
//All when you needs.
return Ok(resMessage);
}
ไล่มาทั้งวัน ผมเสียเวลาไปทั้งวัน สาเหตุมันเป็นเพราะ .NET Core 3.1 มันไม่ได้ใช้ Json.NET มันใช้ตัวนี้แทน Microsoft.AspNetCore.Mvc.NewtonsoftJson
ผมเลยถึงบางอ้อ บางครั้งมันก็ไม่ได้เป็นที่ตัวเรา หรือตัวเขา แต่มันเป็นเหตุสุดวิสัย...
ปล. ผมอัพ VB --> C# ทั้งหมด ผมพยายามทำอยุ่ ไม่รู้เสร็จวันไหน
|
 |
 |
 |
 |
Date :
2019-12-09 21:01:09 |
By :
หน้าฮี |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (C#)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Diagnostics;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
//nuget Microsoft.AspNetCore.Mvc.NewtonsoftJson // .NET Core 2.2 -> 3.1 ฝั่งเรียก Web MVC 3.1 -> ฝั่งรับ Web API 3.1 มีปัญหา
//หมายความว่าใช้ JObject ไม่ได้ อทิเช่น WEB API -> Method Post JObject param
//จำเป็นต้องใส่ในฝั่ง Frontend/Backend(MVC Web/ Web API)
namespace sexyERP.WebApp
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
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.AddControllersWithViews()
.AddRazorRuntimeCompilation()
.AddNewtonsoftJson() //nuget Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation Fixed .cshtml/other change browser not refresh
//.AddApplicationPart(typeof(faceHe_APIServiceSexy.Startup).GetTypeInfo().Assembly); //face He Add before .NET Core 2.2 สำหรับ .NET Core 3.x ไม่จำเป็น
;
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
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(); //face He Comment
app.UseStaticFiles();
app.UseRouting();
//app.UseAuthorization(); //face He Comment
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
});
}
}
}
|
 |
 |
 |
 |
Date :
2019-12-09 21:10:56 |
By :
หน้าฮี |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เหตุผลที่ผม Migrate .NET Core 2.2 --> .NET Core 3.1 มันมีเหตุผลอยุ่ครับ (สำหรับผม VB/C# มันก็ไม่แตกต่างกัน)
แต่เหตุผลหลักก็คือ เก็บเอาไว้อ้างอิง และ
1. เอาไปวิ่งบน Nginx/Apache/etc.. ได้
2. เอาไปวิ่งบน Mac/Linux/etc.. ได้
3. ข้อนี้สำคัญ ผมจะไม่เขียน Windows Application/Web Application อีกแล้ว
แล้วผมไปไหน?
--- Node.js/Dart(Flutter)/Python +55555
|
 |
 |
 |
 |
Date :
2019-12-09 21:28:13 |
By :
หน้าฮี |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขยายความ #1-#2 หรือ Backend/FrontEnd
Code (JavaScript)
<script>
$("#btnSignIn").on("click", function (e) {
e.preventDefault();
doAjax();
});
function doAjax() {
let user = {
username: "Dang",
password: "Slowly As Fuck"
}
//try {
$.ajax({
type: "POST",
url: "/api/Security/SignIn",
data: JSON.stringify(user), //Mapping JObject user
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
//console.log(data);
},
error: function (req, status, error) {
//TODO
alert(error);
}
});
//} catch (error) {
// console.error(error);
//}
}
</script>
|
 |
 |
 |
 |
Date :
2019-12-09 21:34:45 |
By :
หน้าฮี |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณนะคะสำหรับคำตอบ ตอนนี้แก้ไขได้เรียบร้อยแล้วค่ะ มันผิดเพราะว่าพิมพ์โค้ดส่งค่าพารามิเตอร์เกินค่ะ มันเลย error
|
 |
 |
 |
 |
Date :
2019-12-09 21:50:50 |
By :
jirang |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คุณคิดว่า NoSQL/SQL บนโลกใบนี้เอาผมอยู่หรือไม่?
อันนี้ผมใช้ MySQL ยกให้เป็นตัวอย่าง
--- ผมไม่อยากจะเขียน Store Procedure ฝังเอาไว้บน RDBMS แทบจะทุกฯกรณี (ถ้าไม่จำเป็น)
Code (C#)
[HttpGet]
[Route("getMDivisionByJDT")]
public IActionResult getMDivisionByJDT()
{
var db = SexyDatabase.GetCurrentDialect();
var start = (string)HttpContext.Request.Query["start"] ?? "0"; //ตำแหน่งระเบียนปัจจุบัน
var pageSize = (string)HttpContext.Request.Query["length"] ?? "10"; //จำนวนที่แสดงต่อหน้า
var searchValue = (string)HttpContext.Request.Query["search[value]"] ?? ""; //คำค้นหา
var orderColumnIndex = (string)HttpContext.Request.Query["order[0][column]"] ?? "1"; //จัดเรียงที่ Column ถ้าไม่ระบุ = 1
var orderColumnName = (string)HttpContext.Request.Query["columns[" + orderColumnIndex + "][name]"] ?? ""; //จัดเรียงชื่อคลัมภ์
var orderDirection = (string)HttpContext.Request.Query["order[0][dir]"] ?? "asc"; //จัดเรียงแบบ asc/desc
string query = "";
var whereClause = "";
if (orderColumnIndex.ToLower() == "id")
{
whereClause = "Id >=" + searchValue;
} else
{
whereClause = "LIKE '%" + searchValue + "%'";
}
switch (db)
{
case SimpleCRUD.Dialect.SQLServer:
break;
case SimpleCRUD.Dialect.PostgreSQL:
break;
case SimpleCRUD.Dialect.SQLite:
break;
case SimpleCRUD.Dialect.MySQL:
query = @$"-- START TRANSACTION;
SET @recordsTotal := (SELECT count(1) FROM wldb.mdivision);
-- SELECT @recordsTotal := 0;
-- SELECT COUNT(*) INTO @recordsTotal FROM wldb.mdivision;
CREATE TEMPORARY TABLE IF NOT EXISTS temp_cs
AS (
SELECT *
FROM
wldb.mdivision WHERE {orderColumnName} {whereClause} ORDER BY {orderColumnName} {orderDirection});
SET @recordsFiltered := (SELECT count(1) FROM temp_cs);
SELECT *, @recordsTotal AS recordsTotal, @recordsFiltered AS recordsFiltered FROM temp_cs LIMIT {pageSize} OFFSET {start};
DROP TEMPORARY TABLE IF EXISTS temp_cs;
-- COMMIT;
";
break;
case SimpleCRUD.Dialect.Oracle:
break;
case SimpleCRUD.Dialect.DB2:
break;
case SimpleCRUD.Dialect.InfluxDB:
break;
default:
break;
}
var lstMock = new[] { new { Id = 1, code = "", nameth = "", nameus = "", Remark = "" } }.Take(0).ToList();
IEnumerable<dynamic> results1 = null;
IEnumerable<IDictionary<string, dynamic>> results3;
using (var cn = SexyDatabase.SexyConnection(forceOpen : true))
{
results1 = cn.Query<dynamic>(query);
//results3 = cn.Query(query) as IEnumerable<IDictionary<string, dynamic>>;
//results2 = cn.GetList<sexy_Database.Models.Settings.MDivision>();
}
int recordsTotal = 0;
int recordsFiltered = 0;
if (results1.Count() > 0)
{
recordsTotal = (int)(long)(results1.ElementAt(0) as IDictionary<string, object>)["recordsTotal"];
var hum1 = results1.ElementAt(0) as IDictionary<string, object>;
var hum2 = hum1.Count();
recordsFiltered = (int)(long)(results1.ElementAt(0) as IDictionary<string, object>)["recordsFiltered"];
}
foreach (var row in results1)
{
var fields = row as IDictionary<string, object>; //row.Cast<IDictionary<string, object>>()
lstMock.Add(new
{
Id = (int)fields["Id"], //(int)fields["Id"]
code = (string)fields["Code"],
nameth = (string)fields["NameTH"],
nameus = (string)fields["NameUS"],
Remark = (string)fields["Remark"]
});
}
return Ok(new { data = lstMock.ToList(), error = "", recordsTotal = recordsTotal, recordsFiltered = recordsFiltered });
}
|
 |
 |
 |
 |
Date :
2019-12-09 21:53:00 |
By :
หน้าฮี |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
@ jirang ผมลืมบอกไปว่า สมัยก่อน ผมเขียน VB เป็นหลัก ผมเขียน C# ได้แค่งูงูปลาปลา
แต่ในไม่ช้าผมก็คงไม่อยากจะจดจำแต่มันกลับไม่ลืมในภาษา VB/C#
ถ้าคุณพอมีเวลา ลองศึกษาภาษา Python/Dart/etc...
คิดเสียว่า ได้คืบกลับได้ยาวเท่าศอก มันก็อัน(ดุ้นเดียวกัน)
-----
ขอให้โชคดีครับ
|
 |
 |
 |
 |
Date :
2019-12-09 22:41:41 |
By :
หน้าฮี |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|