Solved

Setup ODBC DSN using delphi code

Posted on 2004-08-03
5
2,237 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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
delphi prevent click fast 2 219
Mobile Keyboard covers the display of the TMemo 3 87
Multiple image collision 13 75
creating threads in delphi 1 104
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…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

772 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