We help IT Professionals succeed at work.

Create a system ODBC data source

jsullivan
jsullivan asked
on
536 Views
Last Modified: 2013-12-25
Does anyone know how I can programatically create a System ODBC Data source from VB without directly writing to the registry?  I have looked at the rdoRegisterDataSource RDO function and the SQLConfigDataSource ODBC API call but both of those seem to create User data sources.

My application currently writes directly to the HKEY_LOCAL_MACHINE registry to create our data source, but I'd prefer to use something like rdoRegisterDataSource or SQLConfigDataSource if possible.  Is there another API call which will let me do this?

Thanks.
Comment
Watch Question

Using VB6? If you add the  reference "ODBC Driver & data source Name Fucntions" to your project, you'll gain access to the function "CreateDSN" which is what I believe you want...
<sigh> typo. Should be  "ODBC Driver & Data Source Name Functions"

Author

Commented:
Unfortunately I am using VB5.  I imagine that VB6 must be calling an ODBC32 API call to create the data source, I just don't know what that call is.
One function in ODBC32.dll looks promising, SQLDataSources, but I definitely don't know what it does. Dan Appleman's Win32 API Puzzle Book and Tutorial for Visual Basic Programmers {ISDN 1-893115-0-11}, especially tutorial 9, might be of some help to ya (they have a program, dumpinfo, that works like dumpbin, only better, provided on the CD).

Author

Commented:
SQLDataSources is just used to list the ODBC data sources.  I do not believe it can be used to create them.

Thanks anyway.  Hopefully someone else may know of the API call that I'm looking for.
The package and deployment wizard is using the following .dll when you include the reference I indicated:

ODBCTOOL.DLL

It is part of VB/VStudio 6...

Author

Commented:
Thanks, but I do not have that file.  I'm sure there must be an API call to do what I want to do.  Hopefully someone will know of what it is.

Commented:
The API can only create User DSN's.
The solutions I used was popping up the ODBC (control panel) screen and then send some keys (Using SENDKEYS) to let VB enter all the nessecary stuff!

If you want an example I can give it to you monday (it's a my work ;-))!

D'Mzzl!
RoverM

Commented:
Are you sure you need a system DSN?
The ODBC Drive & Data source tools can only create user ones.
In my current project I've resorted to using user DSNs and checking/setting them up each time the app is run.

Commented:
In the ODBC API, the SQLConfigDataSource function can take a parameter called ODBC_ADD_SYS_DSN -wouldn't that mean that you could create a System DSN?
Hi jsullivan,

There is actually a simple way of creating System DSNs.
All you need is to use the Registry API in order to create an entry in the registry. If you have a look at you current registry under the key HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\odbc.ini, you will find here an entry for all the currently available System DSNs on your machine.
If you want to create an entry programmatically, all you need is to add a new key (and accompanying values) under this registry key.
The values you have to create depend on the type of ODBC driver you will be using... The best thing to figure out what you need, is to create a DSN manually at first, then you can see what entries are needed under this key. You can then write the code to create this type of entries in the registry by code yourself.
If you want to create a User DSN then you should work the same way, but create the entries in the HKEY_CURRENT_USER\SOFTWARE\ODBC\odbc.ini registry key.

Hope this helps....
Let me know if you'd like more details...

Patrick.
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
qcs001, Thanks for your answer.  The ODBC_ADD_SYS_DSN parameter was what I was missing. (wylliker, you mentioned this command as well, but I needed the value of the constant)

PatrickVD, thank you for your comment, but as I mentioned in my original question, I did not want to manually write to the registry.  That is what I was already doing and I wanted to change it to an API call.

Commented:
Glad to be of assistance.

Regards,
Grant Schuleman
South Africa.

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.