Results 1 to 4 of 4

Thread: Microsoft.ACE.OLEDB.12.0 doesn't get the right value in Excel file

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2010
    Posts
    2

    Microsoft.ACE.OLEDB.12.0 doesn't get the right value in Excel file

    Hello ,

    This is incredible.
    We've got a process that read Excel file using a SQL query on Microsoft.ACE.OLEDB.12.0.

    In the Excel file, the cell's value = 0,5
    In the SQL query, the value = 1

    I have tried to save the Excel file as a CSV, and I can see the "0,5".

    We don't understand, we have no clue !!!

    Here is the query :
    SELECT activite.F9
    FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0',
    'Excel 12.0;HDR=YES;IMEX=1;Database=C:\GammaWeb_TMD\Imports\RMA\Arch\RMA201011_Test.xls',
    'SELECT F1,F9 FROM [Activité mensuelle$B20:AJ23]') as activite
    where F1 like 'F%'


    Do you have any advice,
    Thanks in advance,
    Olivier

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Microsoft.ACE.OLEDB.12.0 doesn't get the right value in Excel file

    Welcome to VBForums

    This kind of issue is common when using a non-database as a database, because non-database files do not have the same level of structure as a database.

    With a database each column in a table has a particular data type assigned to it, but that is not the case for non-database files. As such, the database engine (in this case the ACE provider) needs to make an educated guess about what data type each column should be, which can often be wrong - and thus cause errors, and/or "incorrect" values as is happening here.


    There are various ways to deal with it, the best of which is to switch to an actual database of some sort (such as an .accdb/.mdb file, or SQL Server Express).

    If that isn't an option, the most reliable method (but still not guaranteed) is to add a fake row of data to the "top" of the file (which contains values that can only be stored in your ideal data type), which you then ignore in all of your queries etc.

    There are other options, but they are less reliable and they tend to be machine specific (which means your changes can affect [eg: break] other programs, and those programs can change the settings to affect your program).

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 2010
    Posts
    2

    Resolved Re: Microsoft.ACE.OLEDB.12.0 doesn't get the right value in Excel file

    That's very helpful.
    I didn't know this was common issue.

    Quote Originally Posted by si_the_geek View Post
    Welcome to VBForums

    This kind of issue is common when using a non-database as a database, because non-database files do not have the same level of structure as a database.

    With a database each column in a table has a particular data type assigned to it, but that is not the case for non-database files. As such, the database engine (in this case the ACE provider) needs to make an educated guess about what data type each column should be, which can often be wrong - and thus cause errors, and/or "incorrect" values as is happening here.


    There are various ways to deal with it, the best of which is to switch to an actual database of some sort (such as an .accdb/.mdb file, or SQL Server Express).

    If that isn't an option, the most reliable method (but still not guaranteed) is to add a fake row of data to the "top" of the file (which contains values that can only be stored in your ideal data type), which you then ignore in all of your queries etc.

    There are other options, but they are less reliable and they tend to be machine specific (which means your changes can affect [eg: break] other programs, and those programs can change the settings to affect your program).

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Microsoft.ACE.OLEDB.12.0 doesn't get the right value in Excel file

    StG is quite correct, but there is another option when reading Excel or other data files using Jet or ACE, if you have access to the Registry on the machine doing the reading. By default, ACE and Jet read the first 8 rows of data and use that to decide the data type of each column. If the data in those rows of a column is all of the same type then that type is assumed, otherwise it will assume text by default. Any data in the remaining rows that doesn't match those data types will either be massaged or ignored.

    You can change that value of 8 rows if you want. You can set a higher value or you can use zero to specify that all rows are used. This will slow down the reading process but it helps to avoid issues like you're encountering. On a 64-bit machine with Office 2010 installed, the key of interest is:

    HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Office\14.0\Access Connectivity Engine\Engines\Excel

    You would omit the Wow6432Node for 32-bit systems and you would use 12.0 for Office 2007. Under that key is a value named TypeGuessRows, which is set to 8 by default. That's the value you should change.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width