?
Solved

auto install ODBC user DSN ?

Posted on 1998-09-01
2
Medium Priority
?
239 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

Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

Question has a verified solution.

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

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month13 days, 2 hours left to enroll

777 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