Solved

Setup ODBC DSN using delphi code

Posted on 2004-08-03
5
2,203 Views
Last Modified: 2008-03-06
Hie
How can I set up an ODBC DSN [using a text driver (*.txt, *.csv)] in delphi. I can do it using the control panel > administrator tools, but I would like a to create and make a connection using delphi
0
Comment
Question by:prosperkach
  • 5
5 Comments
 
LVL 5

Expert Comment

by:Darth_helge
Comment Utility
function AddDSN(const Database, Description: String): Boolean; begin
 Result := SQLConfigDataSource(0, ODBC_ADD_DSN, //ODBC_ADD_DSN is a constant = 1
   Database, PChar(
   'DSN=MSORCL32_DSN'#0 +
   'PWD=xxxxx'#0 +
   'Server=xxxxx'#0 +
   'Description=' + Description + #0 +

   'UID=xxxxx'#0));
end;

The parameters can be for example:
AddDSN('Microsoft ODBC for Oracle','My Cool Database')

which is for a oracle database
0
 
LVL 5

Expert Comment

by:Darth_helge
Comment Utility
here are the other constants...

 ODBC_ADD_DSN = 1; // Add data source
 ODBC_CONFIG_DSN = 2; // Configure (edit) data source
 ODBC_REMOVE_DSN = 3; // Remove data source
 ODBC_ADD_SYS_DSN = 4; // add a system DSN
 ODBC_CONFIG_SYS_DSN = 5; // Configure a system DSN
 ODBC_REMOVE_SYS_DSN = 6; // remove a system DSN
 ODBC_REMOVE_DEFAULT_DSN = 7; // remove the default DSN
0
 
LVL 5

Expert Comment

by:Darth_helge
Comment Utility
sorry... you have to predeclare the function too

function SQLConfigDataSource(
 hwndParent: HWND;
 fRequest: WORD;
 lpszDriver: LPCSTR;
 lpszAttributes: LPCSTR): BOOL; stdcall; external 'ODBCCP32.DLL';
0
 
LVL 5

Expert Comment

by:Darth_helge
Comment Utility
0
 
LVL 5

Accepted Solution

by:
Darth_helge earned 500 total points
Comment Utility
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

762 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now