Solved

Setup ODBC DSN using delphi code

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

Expert Comment

by:Darth_helge
ID: 11702980
0
 
LVL 5

Accepted Solution

by:
Darth_helge earned 500 total points
ID: 11703002
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

751 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