如上

解决方案 »

  1.   

    ADOConnection1.Connected:=false;
      tempPath:=ExtractFilePath(Application.ExeName)+'\DBNAME.mdb';
      tempStr:='Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source=';
      tempStr:=tempStr+tempPath;
      tempStr:=tempStr+';Mode=ReadWrite;Extended Properties="";';
      tempStr:=tempStr+'Locale Identifier=2052;';
      tempStr:=tempStr+'Persist Security Info=False;';
      tempStr:=tempStr+'Jet OLEDB:System database="";';
      tempStr:=tempStr+'Jet OLEDB:Registry Path="";';
      tempStr:=tempStr+'Jet OLEDB:Database Password="";';
      tempStr:=tempStr+'Jet OLEDB:Engine Type=5;';
      tempStr:=tempStr+'Jet OLEDB:Database Locking Mode=1;';
      tempStr:=tempStr+'Jet OLEDB:Global Partial Bulk Ops=2;';
      tempStr:=tempStr+'Jet OLEDB:Global Bulk Transactions=1;';
      tempStr:=tempStr+'Jet OLEDB:New Database Password="";';
      tempStr:=tempStr+'Jet OLEDB:Create System Database=False;';
      tempStr:=tempStr+'Jet OLEDB:Encrypt Database=False;';
      tempStr:=tempStr+'Jet OLEDB:Don''t Copy Locale on Compact=False;';
      tempStr:=tempStr+'Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False';
      ADOConnection1.ConnectionString:=TempStr;
      TRy
        ADOConnection1.Connected:=True;
      except
        ShowMessage('数据库连接出现错误');    
        exit;
      

  2.   

    const
      connectstringA ='Provider=MSDataShape.1;Persist Security Info=True;Data Source=';
      connectstringB =';Data Provider=Microsoft.Jet.OLEDB.4.0';tempquery:=Tadoquery.create(nil);
      try
        ADOConnection.Free;
              ADOConnection:=TADOConnection.create(Application);
              ADOConnection.connectionstring:=connectstringA + 'd:\test.mdb'
                                             + connectstringB;
              ADOConnection.LoginPrompt:=False;
        tempquery.connection:=AdoConnection;
        tempquery.Close;
        tempquery.SQL.Clear;
        tempquery.SQL.Add(SqlClause);
        tempquery.open;
      

  3.   

    var DataBaseName,
        ConnectStr:ansiString;
        passwordform:tpasswordform;
        i:integer;
        RationDataBaseName : AnsiString;
    begin
      flag:=false;
      listbox1.Items.Clear;
      OpenDialog1.Title:='打开工程项目';
      OpenDialog1.InitialDir := ExtractFilePath(Application.ExeName) + '新建项目';
      if OpenDialog1.Execute then
      begin
        //设置连接字符串
        DataBaseName:=OpenDialog1.FileName;
        ConnectStr:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+DataBaseName+';';
        ProjectDatamodule.ProjectConnection.Connected:=false;
        ProjectDatamodule.ProjectConnection.ConnectionString:='';
        ProjectDatamodule.ProjectConnection.ConnectionString:=ConnectStr+'Persist Security Info=true';
        ProjectDatamodule.ProjectConnection.Connected:=true;
        projectdatamodule.Projectconnection.GetTableNames(listbox1.Items,false);
      

  4.   

    哦。对不起,我想说的是如何调用Delphi中BuildConnectionString的那个界面来生成ConnectionString
      

  5.   

    Adodb.pas中有个函数
    PromptDataSource(handle,'...');//'...'为你初始化的字符串.
    返回的是一个wideString.就是连接.
    可以用它来实现你的要求.
      

  6.   

    var
       InitialString: WideString;
    begin
      InitialString:='';
      InitialString:=PromptDataSource(Handle,'');
      if InitialString<>'' then begin
        ADOConCost.Connected:=False;
        ADOConCost.ConnectionString:= InitialString;
        ADOConCost.Connected:=True;
      end;
    end;
      

  7.   

    用ini文件
        ConnectionString:='Provider=SQLOLEDB.1;Persist Security Info=False'+
                          ';User ID='+username+';Password=sa'+';Initial Catalog=manage'+
                          ';Data Source='+servername+';';
        ADOConnection1.ConnectionString:=ConnectionString;
    manage为库名,此例为sql server2000