German Umlaute Encoding Issue
Posted: 22.03.2016, 16:30
Hi all,
first of all the versions I'm using:
Delphi 10
zeos testing-7.3
FreeTDS from zeos testing
MS SQL Server 2008 (SP2?)
currently I'm facing an issue with the migration from my BDE database to MS SQL Server with the German Umlaute ä,ö,ü
I know this issue has been discussed in severel threads and a lot of possible solutions have been posted, but none is working for me.
I already found out, that the sybdb.dll is ANSI based and that there are some tricks and hooks needed to correctly convert unicode strings.
I've tried both version of sybdb.dll with and without iconv support. And I also tried to declate the varchar fields with nvarchar - but no luck.
When I insert a SQL statement containing special characters I always get this error;
DBError [2402]: Error converting characters into server's character set. Some characters could not be converted...
Incorrect syntax near 'B'.
When I manually replace the a,ö,ü with ae,oe,ue it works. But that's not the way it should be...
As connection parameters I use:
I've also tried it with
In addition I've added all UTF8 related tags I could find.
My insert statement looks like this:
I also tried a workaround like this:
But nothing was working.
Any help is very appreciated!
Best regards,
Bastian
first of all the versions I'm using:
Delphi 10
zeos testing-7.3
FreeTDS from zeos testing
MS SQL Server 2008 (SP2?)
currently I'm facing an issue with the migration from my BDE database to MS SQL Server with the German Umlaute ä,ö,ü
I know this issue has been discussed in severel threads and a lot of possible solutions have been posted, but none is working for me.
I already found out, that the sybdb.dll is ANSI based and that there are some tricks and hooks needed to correctly convert unicode strings.
I've tried both version of sybdb.dll with and without iconv support. And I also tried to declate the varchar fields with nvarchar - but no luck.
When I insert a SQL statement containing special characters I always get this error;
DBError [2402]: Error converting characters into server's character set. Some characters could not be converted...
Incorrect syntax near 'B'.
When I manually replace the a,ö,ü with ae,oe,ue it works. But that's not the way it should be...
As connection parameters I use:
Code: Select all
ClientCodepage=UTF8,
ControlsCodePage=cCP_UTF16,
AutoEncodeStrings=ON
Code: Select all
ClientCodepage=UTF8,
ControlsCodePage=cCP_UTF8,
AutoEncodeStrings=OFF
Code: Select all
// hier das Zeos UTF8 Zeugs
Properties.Clear;
Properties.Add('character_set_client=utf8');
Properties.Add('character_set_connection=utf8');
Properties.Add('character_set_database=utf8');
Properties.Add('character_set_results=utf8');
Properties.Add('character_set_server=utf8');
Properties.Add('character_set_system=utf8');
Properties.Add('collation_connection=utf8_general_ci');
Properties.Add('collation_database=utf8_general_ci');
Properties.Add('collation_server=utf8_general_ci');
Properties.Add('Codepage=utf8');
Code: Select all
var
q, PidIn, ArchivIn, PKlassIn : string;
begin
//Dummy data
PidIn := 'MyIdentifier';
ArchivIn := '0001';
PKlassIn := 'Bööööp'; //<- Problem with this value
//statement
q := 'INSERT INTO MyTable(PROJID,ARCHIV,PKLASS) VALUES (:pid,:archiv,:pklass);';
zQuery.SQL.Clear;
zQuery.SQL.Add(q);
//Add values to statement
zQuery.ParamByName('pid').Value := PidIn;
zQuery.ParamByName('archiv').Value := ArchivIn;
zQuery.ParamByName('pklass').Value := PKlassIn;
zQuery.ExecSQL;
end;
Code: Select all
var
q, PidIn, ArchivIn, PKlassIn : string;
begin
//Dummy data
PidIn := 'MyIdentifier';
ArchivIn := '0001';
PKlassIn := 'Bööööp'; //<- Problem with this value
//modified statement N:pklass
q := 'INSERT INTO MyTable(PROJID,ARCHIV,PKLASS) VALUES (:pid,:archiv,N:pklass);';
zQuery.SQL.Clear;
zQuery.SQL.Add(q);
//Add values to statement
zQuery.ParamByName('pid').Value := PidIn;
zQuery.ParamByName('archiv').Value := ArchivIn;
// tested both ways .AsString and .AsWidString
//also in combination with UTF8Encode(PKlassIn)
zQuery.ParamByName('pklass').AsString / .AsWideString := PKlassIn;
zQuery.ExecSQL;
end;
Any help is very appreciated!
Best regards,
Bastian