Recent

Author Topic: ODBC MSSQL NChar issue  (Read 928 times)

luca

  • Jr. Member
  • **
  • Posts: 83
ODBC MSSQL NChar issue
« on: March 31, 2021, 10:10:19 pm »
I'm importing some data from the ERP to my local app.
ERP and my app are using MSSQL as DBMS.
One field (Name) is defined as nchar(20) in both tables.

I read one record using a query and insert it in destination table using a parametizer query: 
Code: Pascal  [Select][+][-]
  1. qryDEST.ParamByName('NAME').AsWideString:=qryORI.FieldByName('NAME').AsWideString;
If the Name is a string composed only of one byte char all is fine.
If the Name contains 20 chars and one of them is a unicode char (example µ) I received the error from MSSQL: string binary will be truncated.

In Debug I see the right text.

Is it an error in my program or is it a limitation in ODBCConn?

Regards
Luca


Gustavo 'Gus' Carreno

  • Hero Member
  • *****
  • Posts: 1122
  • Professional amateur ;-P
Re: ODBC MSSQL NChar issue
« Reply #1 on: March 31, 2021, 10:37:26 pm »
Hey Luca,

Can't really answer your question 100% and for that I'm sorry.

But in the mean time, let's cover our bases:
  • Are both databases/tables using same charset?
  • If so, are they both Unicode compatible and interchangeable?

If so, then I bow out and let the real experts take charge of this one.

I'm still learning, myself, which type of string to use when dealing with Unicode stuff...

Cheers,
Gus
Lazarus 3.99(main) FPC 3.3.1(main) Ubuntu 23.10 64b Dark Theme
Lazarus 3.0.0(stable) FPC 3.2.2(stable) Ubuntu 23.10 64b Dark Theme
http://github.com/gcarreno

luca

  • Jr. Member
  • **
  • Posts: 83
Re: ODBC MSSQL NChar issue
« Reply #2 on: April 01, 2021, 08:30:01 am »
Hi,
both db are using same charset and they are Unicode compatible.

Regards
Luca

luca

  • Jr. Member
  • **
  • Posts: 83
Re: ODBC MSSQL NChar issue
« Reply #3 on: April 01, 2021, 12:00:25 pm »
I've fixed the problem.
There is another field I didn't convert using AsWideString.

Now it's working.

Regards
Luca

 

TinyPortal © 2005-2018