Solved

auto install ODBC user DSN ?

Posted on 1998-09-01
2
236 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
2 Comments
 
LVL 8

Accepted Solution

by:
Answers2000 earned 100 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Process filename extension 3 196
tripleUp challenge 7 86
Updating statistics with error notification email in SQL server 4 110
Problem to App source 6 75
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

828 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