none
Exception thrown by OleDbConnection.Open() while connecting to mdb file that has foreign characters in its name RRS feed

  • Question

  • I need to read through an mdb file that may or maynot have a name in any foreign language. OleDbConnection.Open() method is throwing exception of 'not a valid file name' when .mdb file name has foreign language characters (I am testing it with russian). It works fine for 'Project.mdb' file but not for 'проект.mdb':

    Just to be clear, the content of file is not an issue here, it is the issue with file's name.What could be the work around here so that same code works for all the languages?

    I tried using Extended Properties=Text;CharacterSet=UTF8; but it does not seem to work either because I get not a valid path exception after making this change.

    var myDataTable = new DataTable();
    string path = "Provider=Microsoft.JET.OLEDB.4.0; Data Source="D:\\test\\проект.mdb";

    using (var conection = new OleDbConnection(path.ToString()))
    {
    int counter = 1;
    conection.Open();
    var query = "Select name From table1";
    var command = new OleDbCommand(query, conection);
    var reader = command.ExecuteReader();
    while (reader.Read() && counter < 2)
    {
    Console.WriteLine(reader[0].ToString());
    counter++;
    }
    }


    Monday, November 13, 2017 9:28 AM

Answers

  • Hi Vishal Gambheer,

    >>Just to be clear, the content of file is not an issue here, it is the issue with file's name. What could be the work around here so that same code works for all the languages?

    According to your description and related code, I reproduce your issue on my side, it seems that Microsoft.JET.OLEDB.4.0 does not support foreign language characters. please change your provider with Microsoft.ACE.OLEDB.12.0, which works on my side.

    var myDataTable = new DataTable();
    string path = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=D:\\test\\проект.mdb";
    
    using (var conection = new OleDbConnection(path.ToString()))
     {
     int counter = 1;
     conection.Open();
     var query = "Select name From table1";
     var command = new OleDbCommand(query, conection);
     var reader = command.ExecuteReader();
     while (reader.Read() && counter < 2)
     {
     Console.WriteLine(reader[0].ToString());
     counter++;
     }
     }
    

    Best regards,

    Cole Wu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, November 14, 2017 2:35 AM
    Moderator

All replies

  • Hi Vishal Gambheer,

    >>Just to be clear, the content of file is not an issue here, it is the issue with file's name. What could be the work around here so that same code works for all the languages?

    According to your description and related code, I reproduce your issue on my side, it seems that Microsoft.JET.OLEDB.4.0 does not support foreign language characters. please change your provider with Microsoft.ACE.OLEDB.12.0, which works on my side.

    var myDataTable = new DataTable();
    string path = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=D:\\test\\проект.mdb";
    
    using (var conection = new OleDbConnection(path.ToString()))
     {
     int counter = 1;
     conection.Open();
     var query = "Select name From table1";
     var command = new OleDbCommand(query, conection);
     var reader = command.ExecuteReader();
     while (reader.Read() && counter < 2)
     {
     Console.WriteLine(reader[0].ToString());
     counter++;
     }
     }
    

    Best regards,

    Cole Wu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, November 14, 2017 2:35 AM
    Moderator
  • Hi Vishal Gambheer,

    The ACE provider is not installed on Windows operating systems by default. You have to install it. The ACE provider is available in two links: Microsoft Office Access database engine 2007 and  the Microsoft Access Database Engine 2010 Redistributable. The 2007 version is only available as a 32-bit component whereas the 2010 version offers both 32 and 64-bit options. please be careful which option you choose, because a wrong choice here is the most frequent cause for the error message.

    Best regards,

    Cole Wu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, November 16, 2017 5:32 AM
    Moderator