How JustAnswer Works:

  • Ask an Expert
    Experts are full of valuable knowledge and are ready to help with any question. Credentials confirmed by a Fortune 500 verification firm.
  • Get a Professional Answer
    Via email, text message, or notification as you wait on our site.
    Ask follow up questions if you need to.
  • 100% Satisfaction Guarantee
    Rate the answer you receive.

Ask Chris Baxter Your Own Question

Chris Baxter
Chris Baxter, Programming Tutor
Category: Programming
Satisfied Customers: 239
Experience:  Completed BSIT concentration Software Engineering, tutored other students and classmates in Java and, C++, and Obj C.
Type Your Programming Question Here...
Chris Baxter is online now
A new question is answered every 9 seconds

I have a need to create ODBC data-source programmatically. I

Customer Question

I have a need to create ODBC data-source programmatically. I have a script that worked on windows XP and now not working on windows 7.
Details of the system and components.
1) Windows 7 64 bit
2) Ms Office 2010. (Tried with both 64 bit and then 32 bit) Also tried with Ms Office 2013.
3) Java 1.7 - 64 bit.
The below windows command is executed by java Runtime object. But this time even if I am runnning the below command on the windows command prompt, I see errors. Oroginally the data source was 2000 Access database format. As I was seeing errors, I have converted to 2002-2003 format, even then I see errors. I have also tried 2007 format, even then I see errors.
Syntax that I have ...
ODBCConf CONFIGSYSDSN "Microsoft Access Driver (*.mdb,*.accdb)" "DSN=SOURCE_2001|Server=C:\SOURCE2001.accdb"
I have also changed the above 'Server' attribute to 'DBQ' no luck. Over all I see the below error.
ONFIGSYSDSN: Unable to create a data source for the 'Microsoft Access Driver' driver:
Component not found in the registry with error code -2147467259
But when I change CONFIGSYSDSN - (System DSN) to CONFIGDSN - (User DSN) then it seems to work but then when Java code tried to access it it says architecture mismatch. Can't seem to find the root cause.
Submitted: 7 months ago.
Category: Programming
Expert:  Chris Baxter replied 7 months ago.


It looks like you are trying to access a protected part of the system directly, when in this case there is an API in place, and no direct programmatic access according to Microsoft. You can see reference and more information at the following link:

There is a method to create a data source programmatically, you just have to use SQL and call the SQLConfigDataSource, below is an example, where you would change the "Excel Files" information to Access file information.

SQLConfigDataSource(NULL,ODBC_ADD_DSN, "Excel Files (*.xls)", "DSN=New Excel Data Source\0" "Description=New Excel Data Source\0" "FileType=Excel\0" "DataDirectory=C:\\EXCELDIR\0" "MaxScanRows=20\0");