0

Information that could be important in advance:

Access 2003 Database (*.mdb)
Table is Linked to SQL Server 2005 Database --> Table
When linked to another Access Database --> Table it works

Program which i use to update : .net 2.0 based C#
Databaselanguage: German?
OleDbConnection used:
 Connection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;" +
                                                 "Data Source=" + PathToDatabase + ";" +
                                                 "Jet OLEDB:System Database=" + PathToSystemFile+ ";" +
                                                 "User ID=" + SignedUserID + ";" +
                                                 "Password=" + SignedLoginKey + ";");

Problem:

i would like to Update a String, which i successfully have parsed to a SQL-Update Statement like:

UPDATE [Artikel] SET [Artikelbeschreibung]='УБИТЬ ДРОЗДА 4 СЕРИИ' WHERE products_id=32501;

my Table [Artikel] contains a row which met the requirements (products_id=32501) when i update the string, no errors or exceptions where thrown. When I check what has arrived in the Database i only see this:

????? ?????? 4 ?????

Encoding from File is UTF8, i've already tried this but with no luck: Convert ANSI (Windows 1252) to UTF8 in C#

here the steps my program do:

 1. Load a file containing the sql statement with placeholder / information in which file, which section, which key the right information will be
  EXAMPLE: UPDATE [Artikel] SET [Artikelbeschreibung]='<<C:\myfile.ini::MySection::MyKey>>' WHERE products_id=32501;

 2. Grab Placeholder / Information
  NOW I HAVE: <<C:\myfile.ini::MySection::MyKey>>

 3. Parse, open File, Search for Section, Search for Key, responding Value of Key as String
  RESPONSE = УБИТЬ ДРОЗДА 4 СЕРИИ

 4. Replace <<C:\myfile.ini::MySection::MyKey>> with УБИТЬ ДРОЗДА 4 СЕРИИ in Original SQL Statement
  RESULT: UPDATE [Artikel] SET [Artikelbeschreibung]='УБИТЬ ДРОЗДА 4 СЕРИИ' WHERE products_id=32501;

 5. Take the string with the Result, open OleDbConnection with Connection as described above and
    do this:
    Connection.Open();
                if (Connection != null)
                {
                    Command = null;
                    Command = Connection.CreateCommand();
                    Command.CommandText = SQL;
                    Command.ExecuteNonQuery();
                    Connection.Close();
                    Connection = null;
                }

 6. Looking into my Database there is only '????? ?????? 4 ?????' instead of 'УБИТЬ ДРОЗДА 4 СЕРИИ'

 Additional Informations: This Only occurs when my Table is linked to a SQL Server, when Table is linked to another Database or is Database directly it works fine.

Maybe someone can help me with this, i dunno where the error might be.

if more information is required then please write, I'll try as soon as possible such documents via "Edit"

Community
  • 1
  • 1
  • Do you pass a literal string or do you build a commandtext and use a parameterized query? – Steve Jun 28 '13 at 15:05
  • I pass a literal string as var named "SQL". Do you think that could be the problem? As i said: if i Update into a mdb file containing "Artikel"-Table as linked from another mdb file it works but if the table is linked via "SQL Server"-ODBC it just messed up – Daniel Alexander Karr Jul 03 '13 at 05:43

1 Answers1

0

You have two options:

  1. Go to Regional Options and set the locale for non Unicode programs to a locale that uses Cyrillic characters.

  2. Convert the Cyrillic string to unicode

    UnicodeFromVal should be set the value of the first Unicode character in the Cyrillic alphabet.

    Public Function AsUnicode(ByVal Source As String, UnicodeFromVal As Long) As String 
    Dim c As Long
    Dim ByteString() As Byte
    Dim AnsiValue As Integer
    Dim Length As Long
    Length = Len(Source)
    ByteString = StrConv(Source, vbFromUnicode, GetSystemDefaultLCID())
    For c = LBound(ByteString) To UBound(ByteString)
        AnsiValue = ByteString(c)
        If AnsiValue >= 224 And AnsiValue <= 250 Then
            AsUnicode= AsUnicode & ChrW(CLng(AnsiValue - 224 + UnicodeFromVal))
        Else
            AsUnicode= AsUnicode & ChrW(AnsiValue)
        End If
    Next
    End Function
    
E Mett
  • 2,272
  • 3
  • 18
  • 37
  • What if my value could be cyrillic and next time german or english? Would that be a problem? Does your code mean i could decode my messed up string directly from file into my database without any need of extra program? How do i handle the return value from your code? My thought is that access 2003 encodes stringstring as ansi not unicode. There i would see a problem to update my tablevalue – Daniel Alexander Karr Jul 03 '13 at 05:48
  • Although MsAccess 2003 supports unciode, VBA does not. Therefore even though your tables support Unicode what you are sending via the VBA has to be converted from ANSI to Unicode. The return value of the function `AsUnicode` is a Unicode string, exactly what you need. If the value is English, then the function can handle it. If it is German you need to change the `UnicodeFromVal` to handle the German characters that are not in the regular English alphabet, such as the umlaut etc. – E Mett Jul 03 '13 at 08:21
  • I see now you are using C#, sorry I missed that before. I wonder if it is stored in your `myfile.ini` as ANSI. Which locale are you using? – E Mett Jul 03 '13 at 08:39
  • i already checked if the "myfile.ini" (i think you mean the file where i put in my update-statements) is ANSI, repaired that it save as UTF-8 without BOM, inside C# the value is UTF-8, it shows up the correct chars (cyrillic) but when using OleDBConnection with ExecuteNonQuery it came up with "????? ?????? 4 ????" instead of "УБИТЬ ДРОЗДА 4 СЕРИИ" – Daniel Alexander Karr Jul 03 '13 at 08:50
  • Currently i'm trying to get this beast beat down by using OleDbParameter but currently with no luck causing lack of "Access Driver" for ODBC, keep you up to date. Thanks in advantage for your help, maybe you'll have another idea what would went wrong inside... it is driving me nuts because: even if i'm connecting my tables by link with ODBC/ MSSQL Server Driver (not the Native Client Driver) i open up the Connection everytime by handling the MDB Database which held the links to this tables. When Tables linked to another MDB Database it works fine. – Daniel Alexander Karr Jul 03 '13 at 08:53
  • I will not work, it drives me to the edge of despair... MDAC / WDAC Driver wont install, when using "Microsoft.Jet.OLEDB.4.0" with OleDbParameter, it wont fill in the Value for '?' --> inside my table there is only the "?" now... using OdbcConnection it says "[HY104] [Microsoft][ODBC Microsoft Access Driver]Invalid precision value"... I slowly run out of ideas... – Daniel Alexander Karr Jul 03 '13 at 09:49