请举例说明:
1:通过ODBC如何连接。
2:通过BDE如何连接。
谢谢!

解决方案 »

  1.   

    BDE:
    procedure TBasDM.DataModuleCreate(Sender: TObject);
    begin
      LoginServer; //连接过程
    end;
    Procedure TBasDM.LoginServer;
    var tempIni: TIniFile;
    tmpServerFrm: TServerFrm;
                    i:Integer;
                    tmpList:TStringList;
                    IsAliasName:Boolean;
    begin  IsAliasName:=false;
    tmpList:= TStringList.Create;
    try
       Session.GetAliasNames(tmpList);
      for I := 0 to tmpList.Count - 1 do
          if tmpList[i]='CostingDB' then
    IsAliasName:=true;    if not IsAliasName then
       Session.AddAlias('CostingDB','MSSQL',CostDB.Params);
    finally
       tmpList.Free;
    end;  if CostDB.Connected then
        CostDB.Connected := False;
      pubLocaOption := [loCaseInsensitive, loPartialKey];
      InitDBbasefile;   //过程名
      with CostDB.Params do
      begin
        Values['SERVER NAME']     := curServerName;
        Values['DATABASE NAME']   := curDBName;
        Values['USER NAME']       := 'sa';
        Values['PASSWORD']        := '';
      end;
      try
          CostDB.Open;
      except
      if Application.MessageBox('数据库连接失败,要重新设置吗?','系统',
       MB_ICONQUESTION+MB_YESNO)=ID_YES then
        begin
          tmpServerFrm:=TServerFrm.Create(Application);
          tmpServerFrm.ShowModal;
          if tmpServerFrm.ModalResult = mrOk then
     begin
            curServerName := tmpServerFrm.Edit1.Text;
               curDBName := tmpServerFrm.Edit2.Text;
               tempIni := TIniFile.Create(ExtractFilePath(Application.ExeName)+'Costing.ini');
               tempIni.WriteString('SYSTEM', 'SERVER', curServerName);
       tempIni.WriteString('SYSTEM', 'DBNAME', curDBName);
       tmpServerFrm.Free;
       tempIni.Free;
     end;
        end
        else
         begin
          Application.Terminate;
         end;
        end;
    end;procedure TBasDM.InitDBbasefile;
    var
    tempIni: TIniFile;
    tmpServerFrm: TServerFrm;
    begin
            tempIni := TIniFile.Create(ExtractFilePath(Application.ExeName)+'Costing.ini');
    curServerName := tempIni.ReadString('SYSTEM', 'SERVER', '');
    curDBName := tempIni.ReadString('SYSTEM', 'DBNAME', '');
            curAutoCADPath := tempIni.ReadString('WinExePath', 'AutoCADPath', '');
            curWordPath := tempIni.ReadString('WinExePath', 'WordPath', '');
            curExcelPath := tempIni.ReadString('WinExePath', 'ExcelPath', '');
    if (curServerName = '') or (curDBName = '') then
    begin
    tmpServerFrm := TServerFrm.Create(Application);
    tmpServerFrm.ShowModal;
    if tmpServerFrm.ModalResult = mrOk then
    begin
    curServerName := tmpServerFrm.Edit1.Text;
    curDBName := tmpServerFrm.Edit2.Text;
    tempIni.WriteString('SYSTEM', 'SERVER', curServerName);
    tempIni.WriteString('SYSTEM', 'DBNAME', curDBName);
    tmpServerFrm.Free;
    end
    else
    begin
    tmpServerFrm.Free;
    Halt;
    end;
    end;
    tempIni.Free;
    end;
      

  2.   

    首先十分感谢,但BDE是否需要连接配置。
      

  3.   

    对不起,我要连接ORACLE数据库
      

  4.   

    BDE连接是比较方便的。 具体设置是:如果连接mssql,必须安装她的驱动程序,然后在bde面板中新建一个数据库,选择驱动程序,选择mssql的数据库。 连接,一般还要输入密码,就ok了!! 
    对于odbc,我没做过。 我不太喜欢odbc。呵呵
      

  5.   

    对不起,我要连接ORACLE8数据库,如何?
    请指教!
      

  6.   

    是远程连接ORACLE,如何设置?