我想做一个程序,动态连接数据库文件,在用户机子上不安装Sql Server,而是安装msde,在Delphi6程序内,如何用语句写呢?

解决方案 »

  1.   

    一样的吧. 你用一个ADO控件, 先用控件的向导把连接做成功, 然后把连接成功的 connectionstring 拷贝出来, 接着你要动态连接的话,只要改变这个 connectionString 串中的 数据源,用户, 密码,数据库对应的值就可以了,再把修改过的串值赋给 ado, 连吧
      

  2.   

    同意!
        s:='Provider=SQLOLEDB.1;Password='+UserPass+';Persist Security Info=True;'+
           'User ID='+UserName+';Initial Catalog='+DataBaseName+';'+
           ' Data Source='+ServerName+';';
      

  3.   

    s:='Provider=SQLOLEDB.1;Password='+UserPass+';Persist Security Info=True;'+
           'User ID='+UserName+';Initial Catalog='+DataBaseName+';'+
           ' Data Source='+ServerName+';';
      

  4.   

    //连接数据库
    function tdmodule.connectedDB(var msg:string):boolean;
    begin
      if ADOConnection1.Connected then
         Result:=True
      else
      begin
      try
        ADOConnection1.ConnectionString:=getStr;
        adoconnection1.LoginPrompt:=false;
        adoquery1.Connection:=ADOConnection1;
        if length(trim(ADOConnection1.ConnectionString))=0 then
        begin
          msg:='错误的连接字符串!';
          Result:=False;
        end
        else
        begin
          ADOConnection1.Connected:=True;
          Result:=True;
        end;
      except
        msg:='无法建立数据库连接!';
        Result:=False;
      end;
      end;
    end;//得到连接字符串
    function tdmodule.getstr():string;
    var path:String;
        tmp:TStrings;
        counter:Integer;
        myIniFile:Tinifile;//配置文件
    begin
      tmp:=TStringList.Create;
      try
        path:=ExtractFilePath(Application.Exename);
        myIniFile:=TiniFile.Create(path+'database.ini');
        myIniFile.ReadSectionValues('database',tmp);
        Result:=' ';
        for counter:=0 to tmp.Count-1 do
          Result:=Result+tmp.Strings[counter];
      finally
        tmp.Free;
      end;
    end;
    两个函数读取database.ini并且用adoconnection连接的
      

  5.   

    请教database.ini 是个什么文件?