Solved

Setup ODBC DSN using delphi code

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

Accepted Solution

by:
Darth_helge earned 500 total points
ID: 11703002
0

Featured Post

Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

Question has a verified solution.

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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses
Course of the Month11 days, 9 hours left to enroll

623 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