我在窗体创建的时候,来连接数据库。我是用ado的。代码如下:
procedure TForm1.FormCreate(Sender: TObject);
var
SYSINI: TINIFile;
filename:string;
begin
         ADOConnection1.Connected := False;
        if ADOConnection1.Connected = False then
        begin
          try
            filename:=extractfilepath(paramstr(0))+'\ini\server.ini';
            sysini:=tinifile.Create(filename);
            UserName := SYSINI.ReadString('Database', 'UserName', '');
            InitDB := SYSINI.ReadString('Database', 'InitDB', '');
            Password := SYSINI.ReadString('Database', 'Password', '');
          finally
          SYSINI.Free;
          end;
         end;
      ADOConnection1.ConnectionString :=
      'Provider=SQLOLEDB.1;'
      +'Password='+Password+';'
      +'Persist Security Info=True;'
      +'User ID='+UserName+';'
      +'Initial Catalog='+initdb+';'
      +'Data Source='+ServerName+';'
      +'Use Procedure for Prepare=1;'
      +'Auto Translate=True;'
      +'Packet Size=4096;'
      +'Workstation ID='+ServerName+';'
      +'Use Encryption for Data=False;'
      +'Tag with column collation when possible=False' ;
      try
     ADOConnection1.Connected := True;
   except
     showmessage('CONNECTION IS WRONG cant found the sql server!');
     application.Terminate ;
   end;end;procedure TForm1.Button2Click(Sender: TObject);
begin
      FORM1.ADOQuery1.Connection:=form1.ADOConnection1;
      form1.ADOQuery1.Close ;
      form1.ADOQuery1.SQL.Clear ;
      form1.ADOQuery1.SQL.Add('select * from PYJ');
      form1.ADOQuery1.Open;
      form1.DataSource1.DataSet:=form1.ADOQuery1;
      form1.DBGrid1.DataSource:=form1.DataSource1;
end;
ini文件如下:
[Database]
ServerName=192.168.0.1
InitDB=LEW            
UserName=GUEST_USER  
Password=WXYJ       
我的问题是,我在本机,使用一切正常,但是我把程序copy到别的电脑上面就 不可以拉。
这是为什么呢?在本机的时候,安装数据库的时候,我是用sa验证,录入了sa的密码,然后我在数据库里面建立了一个用户,GUEST_USER,密码是:WXYJ,我是想在写程序的时候,用GUEST_USER来验证的。在别的电脑上面使用,提示。showmessage('CONNECTION IS WRONG cant found the sql server!');,就是连接数据库不能通过。

解决方案 »

  1.   

    //oracle数据库连接
      if Edt_Machine.Text ='' then
      begin
       messagebox(handle,'服务器名不能为空,请重新输入!','提醒!!',mb_iconinformation);
       Edt_Machine.SetFocus;
       exit;
      end;
      if rbt_db.Checked =true then
        begin
         Dm.adc_connect.Close;
         Dm.adc_connect.ConnectionString:='';
         Dm.adc_connect.ConnectionString:=format(ora_constring,[Edt_Password.Text,
                                                          Edt_Username.Text,
                                                          Edt_Machine.text]);
        try
         Dm.adc_connect.Connected :=true;
         messagebox(handle,'数据库连接成功!','注意',mb_iconinformation);
         frmconnect.Hide;
         frmselect.show;
        except
         messagebox(handle,'数据库连接失败!','注意',mb_iconinformation);
         Dm.adc_connect.Close;
        end;
      end;
      

  2.   

    你可在别的电脑上增
    加SA用户,设置登录密码为GEST_USER