0
votes

On Azure App service, my application use Microsoft.Jet.OLEDB.4.0 to read my file with japanese file name. It worked well until 2017/09/21, but it throw exception from 2017/09/22. It only read file without japanese file name. If to read one with japanese file name, it throw exceptions are as follows

System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr) at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) at System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior) at System.Data.OleDb.OleDbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior) at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) at System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior) at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)

I asked Microsoft support site, but no useful answer. Has my codes some wrong ?

my code:

   public static DataTable readCSV(string filePath)
    {
        DataTable dt = new DataTable();
        if (File.Exists(filePath) == false)
        {
            return dt;
        }

        string header = "No";
        string pathOnly = Path.GetDirectoryName(filePath);
        string fileName = Path.GetFileName(filePath);

        FileInfo fInfo = new FileInfo(filePath);
        FileInfo dinfo = new FileInfo(pathOnly);
        if (dinfo.IsReadOnly)
        {
            dinfo.IsReadOnly = false;
        }

        if (fInfo.IsReadOnly)
        {
            fInfo.IsReadOnly = false;
        }
        var encoding = Encoding.GetEncoding(932);
        using (StreamReader reader = new StreamReader(filePath, Encoding.GetEncoding(932), true))
        {
            reader.Peek(); // you need this!
            encoding = reader.CurrentEncoding;
        }
        string sql = @"SELECT * FROM [" + fileName + "]";

        using (OleDbConnection connection = new OleDbConnection(
                  @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + pathOnly +
                  ";Extended Properties=\"Text;IMEX=1;CharacterSet=" + encoding.CodePage + ";HDR=" + header + "\""))
        using (OleDbCommand command = new OleDbCommand(sql, connection))
        using (OleDbDataAdapter adapter = new OleDbDataAdapter(command))
        {
            DataTable dataTable = new DataTable();
            dataTable.Locale = CultureInfo.CurrentCulture;
            adapter.Fill(dataTable);

            return dataTable;
        }
    }
1
For reading excel (xls, xlsx) files, I would prefer to leverage NPOI, you could refer to this sample and issue. For reading the csv files, you could use LumenWorks.Framework.IO, CsvHelper, etc.Bruce Chen
@ Bruce Chen, thanks. Are you test NPOI can read japanese file with japanese filename ON Azure App service afer 2017/09/22?jmdc
I did not test it for reading Japanese file yet, I would check it later.Bruce Chen

1 Answers

1
votes

This might be caused by Windows security update KB4041681. At https://social.technet.microsoft.com/Forums/en-US/55b1d633-b715-491e-917e-b7cb01ae0523 several people have reported that uninstalling that update has solved their problems. Another solution is to use the Microsoft.ACE.OLEDB.12.0 driver instead of of Microsoft.Jet.OLEDB.4.0.