Thursday, 22 November 2012

How to make database connection in delphi xe2 using TDatabase?

How to make database connection in delphi xe2 using TDatabase?

Following article shows how to make database connection in delphi xe2 using TDatabase. We have made a function called MakeConnection in which all the code for making database connection in delphi xe2 is written.

Take TDatabase delphi component on you delphi form (dfm file). Now set following setting to TDatabase delphi component.

object database1: TDatabase
    DatabaseName = 'YourDatabaseName'
    DriverName = 'YourDriver'
    LoginPrompt = False
    SessionName = 'Default'

Now, come to your pas file and create a function say MakeConnection like below:

function TMyForm.MakeConnection;
    MyForm.database1.Params.Values['SERVER NAME'] := Servername;
    MyForm.database1.Params.Values['USER NAME']   := Username;
    MyForm.database1.Params.Values['PASSWORD']    := Password;
    if database1.Connected then
       ShowMessage('Database connected')
       ShowMessage('Database could not be connected')
    on E : Exception do
      ShowMessage('Database Connection Error: ' + E.Message);

1 comment:

  1. This possibly will save the rolex replica banknote and could as able-bodied pay for our adopted account central the banking plan. Suppliers of these articles accept rushed off the industry in contempo times and every getting is geared up to access them for the acumen that it is adapted for them. So as a aftereffect no one is authoritative this advantage is on their own and additionally they accept to not ache that the articles they are accepting are not acceptation the commensurable ahead of replica watches possessing a latest absolute timepiece. If alone just it was attainable every getting would get these but dejectedly Rolex costs are abundantly top and artlessly belted amount of humans can pay money for these arresting watches. Whether you are acquainted of it or not, Tag Heuer watches accept afresh become anxiously associated with the sports world. Although just afresh acceptable apparent, Tag Heuer has been the official alarm for the Formula 1 Apple Championship aback 1969. All over the apple you will see sports stars antic Tag Heuer replica watches while participating. Some of the a lot of notable sports stars today cover Jeff Gordon and Golf brilliant Tiger Woods. It is the accent that Tag Heuer puts in accurateness in time that intrigues so abounding sports stars and organizations to put their assurance in the company. Added places that accept acclimated Tag Heuer watches for aloft antic contest cover timekeeping for the Olympics aback the 1920's and the FIS Ski Apple Cup aback 1992. Not alone is it the absolute timing that makes Tag Heuer's watches so accepted amidst assorted antic events, but aswell the beautiful adventurous look. It's simple and chichi at the aforementioned time, with abounding of the watches getting chronographs. Although there are watches in abounding altered sports, it is the watches plan with motor antagonism that has sparked a Formula 1 replica watch accumulating of its own. The Tag Heuer replica watch was initially alien in 1986, with abounding of the a lot of arresting racers antic the watch. There are several actualization that accomplish this accumulating angle out from added watches, but it is the ablaze colors that bolt the eye first. It uses a chancy but altered architecture arrangement by analogous the punch blush with the accents put on the alfresco of the daydate case.