Solved

Database COnnection with Delphi

Posted on 2006-07-16
5
231 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
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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

773 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