我刚接触DELPHI,想了解一点数据库的问题.问题就是:我看见有的程序在系统登录的时候,在登录窗口上,有一个配置数据库的按纽.点击之后就弹出DELPHI带的配置数据库的窗口,我现在也想这样做.请各位指教.我应该如何处理?
或者能否告诉我其他的配置数据库的方法(DELPHI7+SQL2000)?
谢谢各位.

解决方案 »

  1.   

    可以使用WINDOWS自带的数据库设置对话框。
    1.连接字符串 
     ConnectionString.Text := PromptDataSource(Handle,'');
    2.连接文件
     DataLinkFile.Text := PromptDataLinkFile(Handle,'');
      

  2.   

    参考一下
    我一般是这样写的
    1、我新建一个INI的文件,把连接数据库的参数写在里面。
    2、运行程序时,可以从INI中得到数据库的连接信息。
    3、需要修改的时候,做一个配置界面,读出INI中的数据库参数,进行修改-->保存。
      

  3.   

    调用api函数,会自动弹出的。最好是用ini文件或者读写注册表
      

  4.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, Buttons, Grids, DBGrids, DB, ADODB,inifiles, ExtCtrls;type
      TForm1 = class(TForm)
        BitBtn1: TBitBtn;
        ADOConnection1: TADOConnection;
        LabeledEdit1: TLabeledEdit;
        LabeledEdit2: TLabeledEdit;
        LabeledEdit3: TLabeledEdit;
        LabeledEdit4: TLabeledEdit;
        BitBtn2: TBitBtn;
        procedure BitBtn1Click(Sender: TObject);
        procedure BitBtn2Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.BitBtn1Click(Sender: TObject);
    begin
      close;
    end;function   GetConnectionString:   string;
      var
          SYSINI:   TINIFile;
          ServerName,   UserName,   Password,   InitDB:   string;
          tmpstr:   string;
          pathconfigstr :string;  begin
          pathconfigstr:= ExtractFilePath(Application.ExeName);
          if pathconfigstr[length(pathconfigstr)]='\' then
             begin
                  pathconfigstr:=pathconfigstr+'db.ini';
                  SYSINI:=Tinifile.Create(pathconfigstr)   ;
             end
         else
            begin
              pathconfigstr:=pathconfigstr+'\db.ini';
              SYSINI:=Tinifile.Create(pathconfigstr)
         end;     if not FileExists(pathconfigstr) then
         begin
         application.MessageBox('配置文件不存在!','提示',mb_ok);
         application.Terminate;
         end;           try
              ServerName   :=   SYSINI.ReadString('Database',   'ServerName',   '');
              UserName   :=   SYSINI.ReadString('Database',   'UserName',   '');
              InitDB   :=   SYSINI.ReadString('Database',   'databasename',   '');
              tmpstr   :=   SYSINI.ReadString('Database',   'Password',   '');
              Password   :=   tmpstr;
              Result   :=   '';   
              Result   :=   'Provider=SQLOLEDB.1;Password='   +   Password   +   ';Persist   Security   Info=false;User   ID='   +   UserName   +   ';Initial   Catalog='   +   InitDB   +   ';Data   Source='   +   ServerName;      finally
              SYSINI.Free;
          end;
      end;procedure TForm1.BitBtn2Click(Sender: TObject);
    begin
       ADOConnection1.Close;
      ADOConnection1.ConnectionString := '';
      ADOConnection1.ConnectionString :=  GetConnectionString;
      try
        begin
         ADOConnection1.Connected := true;     labelededit1.text := GetConnectionString;
        end;
      except
           application.MessageBox('数据库配置不正确,请重新配置!','提示',mb_ok);
           ADOConnection1.Connected:=false;
           application.Terminate;
      end;end;end.
    问题是:只要一点击数据库连接按钮,就出现'字符串连接属性出错.'不知道什么原因,请指教.
    在线等.
      

  5.   

    配置文件是:
    [database]   
    ServerName=127.0.0.1
    UserName=sa  
    Password=  
    databasename=test 
      

  6.   


    一般都是弹出窗口,写入配置信息到ini文件中..
    程序每次开启时候读取该配置信息窗口。。
    连接不上或者连接失败,重新显示该窗口重新配置的.
      

  7.   

    用adoconnect.promptdatasource()就可以了,具体使用看一下它的单元文件