Delphi ODBC Connection Dialog Component?

I am thinking of connecting an ODBC database to an application.

The user will configure and select a connection to the odbc database at runtime.

Are there any components that will give me the necessary series of dialogs?

Allowing the user to select the type of data source, select the drivers, view already defined ODBC connections, etc.

Cheers Sam

+5
source share
2 answers

You can try this if you are using ADO components.

Option 1

  Uses
    OleDB,
    ComObj,
    ActiveX;

    function Edit_ADO_ODBC_ConnectionString(ParentHandle: THandle; InitialString: WideString;out NewString: string): Boolean;
    var
      DataInit  : IDataInitialize;
      DBPrompt  : IDBPromptInitialize;
      DataSource: IUnknown;
      InitStr   : PWideChar;
    begin
      Result   := False;
      DataInit := CreateComObject(CLSID_DataLinks) as IDataInitialize;
      if InitialString <> '' then
      DataInit.GetDataSource(nil, CLSCTX_INPROC_SERVER, PWideChar(InitialString),IUnknown, DataSource);
      DBPrompt := CreateComObject(CLSID_DataLinks) as IDBPromptInitialize;

      {
      DBPROMPTOPTIONS_WIZARDSHEET = $1;
      DBPROMPTOPTIONS_PROPERTYSHEET = $2;
      DBPROMPTOPTIONS_BROWSEONLY = $8;
      DBPROMPTOPTIONS_DISABLE_PROVIDER_SELECTION = $10;
      }
      if Succeeded(DBPrompt.PromptDataSource(nil, ParentHandle,DBPROMPTOPTIONS_PROPERTYSHEET, 0, nil, nil, IUnknown, DataSource)) then
      begin
        InitStr   := nil;
        DataInit.GetInitializationString(DataSource, True, InitStr);
        NewString := InitStr;
        Result    := True;
      end;
    end;



Result:=Edit_ADO_ODBC_ConnectionString(0,OldConnectionString,NewString);

Option 2

Uses
ADODB;

PromptDataSource(Self.Handle, InitialString);

Option 3

Uses
ADODB,
AdoConEd;

procedure TMainForm.Button2Click(Sender: TObject);
Var
ADOConnection1 : TADOConnection;
begin
   ADOConnection1:=TADOConnection.Create(Self);
   EditConnectionString(ADOConnection1);
end;

You must select "Microsoft OLE DB Provider for ODBC Drivers"

Bye

+9
source

PromptDataSource ADODB. : :

  • . :

    var sConn : WideString; begin sConn := PromptDataSource(Form1.Handle, ''); end;

0

All Articles