Solved

Setup ODBC DSN using delphi code

Posted on 2004-08-03
5
2,251 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
ID: 11702903
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
ID: 11702913
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
ID: 11702942
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
ID: 11702980
0
 
LVL 5

Accepted Solution

by:
Darth_helge earned 500 total points
ID: 11703002
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

840 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