Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

auto install ODBC user DSN ?

Posted on 1998-09-01
2
Medium Priority
?
240 Views
Last Modified: 2013-11-20
Please, how do I automatically install/configure a new User DSN for ODBC support ?

My software is using ODBC access method and I prefer it if the user does not have to technically configure this himself before my software runs on his computer - can I do this in my install code, and if possible how ?

Thanks,

Ernesto
0
Comment
Question by:cpdata
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 8

Accepted Solution

by:
Answers2000 earned 400 total points
ID: 1321581
There's an API called SQLConfigDataSource which I believe does exactly what you need.

The example from the Dev Studio help is



(begin quote)
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");
(end quote)

The rest of the answer below is a combination of cut'n'pastes fom the help, with my own tweaks (some of the quote brackets may in the wrong place)

To use ::SQLConfigDataSource, you must include the ODBCINST.H header file and use the ODBCINST.LIB import library. Also, ODBCCP32.DLL must be in the path at run time (or ODBCINST.DLL for 16 bit).

(begin quote)

Function Prototype

BOOL SQLConfigDataSource(HWND hwndParent,UINT fRequest, LPCSTR lpszDriver, LPCSTR lpszAttributes);

Parameters and Usage

hwndParent The window specified as the owner of any dialog boxes that either the ODBC Driver Manager or the specific ODBC driver creates to obtain additional information from the user about the new data source. If the lpszAttributes parameter doesn't supply enough information, a dialog box appears. The hwndParent parameter may be NULL; see the ODBC Programmer's Reference for details.

lpszDriver The driver description. This is the name presented to users rather than the physical driver name (the DLL).

lpszAttributes List of attributes in the form "keyname=value". These strings are separated by null terminators with two consecutive null terminators at the end of the list. These attributes are primarily default driver-specific entries, which go into the registry for the new data source. One important key that is not mentioned in the ODBC API reference for this function is "DSN" ("data source name"), which specifies the name of the new data source. The rest of the entries are specific to the driver for the new data source. Often it is not necessary to supply all of the entries because the driver can prompt the user with dialog boxes for the new values. (Set hwndParent to NULL to cause this.) You might want to explicitly supply default values so that the user is not prompted.

(end quote)

You can also do the same thing by writing to the registry yourself (somebody may suggest it), but this is dependant on which ODBC version you have.  The above solution is generic for all versions.


Is this enough or do you need more.  Sorry if this is a bit disjointed as I've been cutting and pasting...
0
 

Author Comment

by:cpdata
ID: 1321582
Fantastic - just what I was looking for  - thanks a lot !
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question