Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

database - Delphi ODBC Connection Dialog Component?

I am thinking about adding ODBC database connectivity to an application.

The user will at runtime configure and select their database odbc connection.

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

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

Cheers Sam

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...