Solved

Database COnnection with Delphi

Posted on 2006-07-16
5
233 Views
Last Modified: 2010-04-05
Dear Expert
I'm a beginner of Delphi programming and want to know the Database Connection of Delphi with any kind of database like Access,Oracle,mysql etc.Pls help me providing code to connect Delphi with 1) Access 2)Oracle and 3) Mysql.

Thanks in advance
0
Comment
Question by:binita11
[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 Comments
 
LVL 17

Accepted Solution

by:
TheRealLoki earned 43 total points
ID: 17116885
This depends on your version of delphi.
but take a look in your program files\delphix\demos\ directory
there are some database demos there
0
 
LVL 9

Assisted Solution

by:sun4sunday
sun4sunday earned 41 total points
ID: 17117090
Here you can begin with  Fundamentals of Database Development

http://delphi.about.com/od/beginners/l/aa020601a.htm

sun4sunday
0
 
LVL 1

Assisted Solution

by:Tueblo
Tueblo earned 41 total points
ID: 17117093
The easiest waywould be to create a datasource in windows for your database. (Control panel, Administrative tools)

uses SysUtils, ActiveX, adoDB, DB, ...;

type

  TForm1 = class(TForm)
  :
  private
    FConnection : TADOConnection;
  :
  end;

functionTForm1.DatabaseConnect: Boolean;
begin
  result := TRUE;
  OleInitialize(nil);
  FConnection := TADOConnection.Create(NIL);
  FConnection.LoginPrompt := TRUE;
  FConnection.ConnectionString := PromptDataSource(0, '');
  try
    FConnection.Open;
  except
    result := FALSE;
  end;
end;

procedure TForm1.DatabaseDisconenct;
begin
  FConnection.Close;
  FreeAndNil(FConnection);
  OleUninitialize;
end;

If you do not want to have the promt dialog every time, you can also give the connection string explicitly. Example for a mySQL Database (the mentioned driver must be installed, check in the datasource dialog):

function TForm1.DatabaseConnect(databaseServer, databaseName, username, password: String): Boolean;
var connectionString : String;
begin
  result := TRUE;
  OleInitialize(nil);
  FConnection := TADOConnection.Create(NIL);
  FConnection.LoginPrompt := FALSE;
  connectionString := 'DRIVER={MySQL ODBC 3.51 Driver}; ' +
                       'SERVER=' + databaseServer + '; '   +
                       'DATABASE=' + databaseName + '; '   +
                       'UID=' + username + '; '            +
                       'PWD=' + password + '; '            +
                       'OPTION=3';
  FConnection.ConnectionString := connectionString;
  try
    FConnection.Open;
  except
    result := FALSE;
  end;
end;
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying 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

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…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

749 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