c# - Get a list of all Access ACE.OLEDB drivers installed on the system -


using following code can enumerate oledb providers registered on system

static void displaydata() {    var reader = oledbenumerator.getrootenumerator();     var list = new list<string>();    while (reader.read()) {       (var = 0; < reader.fieldcount; i++) {          if (reader.getname(i) == "sources_name") {             list.add(reader.getvalue(i).tostring());          }       }       console.writeline("{0} = {1}", reader.getname(0), reader.getvalue(0));    }    reader.close(); } 

it returns list of drivers (we interested in access drivers) 1 caveat..

against .net 4.5 contains:

sources_name = microsoft.ace.oledb.15.0

but when project built against .net 4.0 output is:

sources_name = microsoft.ace.oledb.12.0

the machine testing on has 32 bit office 2013 installed (which has microsoft.ace.oledb.15.0) , have installed 64 bit version of access database driver (which has microsoft.ace.oledb.12.0). project running set anycpu, using windows 8.1.

why doesn't enumeration return same results?

how can list of providers installed on system? reason want want run against latest driver, connections need use earlier version of driver. (this because need upgrade of old .mdb files) if older version not installed want inform users.

miscellaneous weirdness:

if create console app against .net 4.5.1 change .net 4.0 , run change .net 4.0 continues return .net 4.0 results (the microsoft.ace.oledb.12.0 driver)

what see here effect of new subtype of anycpu setting called anycpu 32-bit preferred has been introduced in .net 4.5. subtype new default new projects. means following:

  • if process runs on 32-bit windows system, runs 32-bit process. il compiled x86 machine code.
  • if process runs on 64-bit windows system, runs 32-bit process. il compiled x86 machine code.
  • if process runs on arm windows system, runs 32-bit process. il compiled arm machine code.

the reasoning behind new default explained in blog post:

what anycpu means of .net 4.5 , visual studio 11

so why see difference in case? if target .net 4.0, application executed within 64-bit process (because of anycpu platform target). hence, see 64-bit version of driver.

if create new project targeting .net 4.5 though, application runs (with default project settings) within 32-bit process, , see 32-bit version of driver.

note should see difference if create new .net 4.5 project; if change .net target version 4.0 4.5, platform target wouldn't change anycpu anycpu 32-bit preferred.


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -