+ -
当前位置:首页 → 问答吧 → deliph连接数据库

deliph连接数据库

时间:2011-09-24

来源:互联网

deliph连接数据库老是说连接属性错误,晕死了,求大师解决代码如下:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs,Grids,DBGrids,DB,ADODB,Stdctrls,ExtCtrls;

type
  TForm1 = class(TForm)
  vdbfname: TEdit;
  Label1: TLabel;
  Label2: TLabel;
  vservername: TEdit;
  Label3: TLabel;
  vusername: TEdit;
  Label4: TLabel;
  upassword: TEdit;
  vtablename: TComboBox;
  Label5: TLabel;
  bottom1: TButton;
  botton2: TButton;
  ADOConnection1: TADOConnection;
  DBGrid1: TDBGrid;
  DataSource1: TDataSource;
  ADOTable1: TADOTable;
  procedure buttom1click(sender:tobject);
  procedure botton2click(sender:tobject);

  private
  { Private declarations }
  public
  { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}
  procedure TForm1.buttom1click(sender: TObject);
  var
  s:string;
  begin
  adoconnection1.Connected:=false;
  s:='Provider=SQLOLEDB.1;Password='+trim(upassword.text)+';Persist Security Info=True;';
  s:=s+'User ID='+trim(vusername.text)+';Initial Catalog='+trim(vdbfname.text)+';Data Source='+trim(vservername.text)+';';
  s:=s+'Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;';
  s:=s+'Use Encryption for Data=False;Tag with column collation when possible=False';
  adoconnection1.connectionstring:=s;
  adoconnection1.loginprompt:=false;
  adoconnection1.connectiontimeout:=3;
  adoconnection1.connected:=true;
  adotable1.Active:=false;
  adotable1.Connection:=adoconnection1;
  adotable1.TableName:=trim(vtablename.Text);
  adotable1.Active:=true;
  datasource1.DataSet:=adotable1;
  dbgrid1.datasource:=datasource1;
  vservername.SetFocus;
  end;
  procedure tform1.botton2click(sender: TObject);
  begin
  close;
  end;


end.

作者: cllmxy   发布时间: 2011-09-24

1、你可以先通过Tadoconnection连接向导,先建立一次连接数据库,并测试连接成功。
2、在通过手工书写连接字符串的方式,并用showmessage(s),查看是不是有错,并与第1步的比较

一般就可以自己查出原因了。

作者: tgbd   发布时间: 2011-09-25

引用 1 楼 tgbd 的回复:
1、你可以先通过Tadoconnection连接向导,先建立一次连接数据库,并测试连接成功。
2、在通过手工书写连接字符串的方式,并用showmessage(s),查看是不是有错,并与第1步的比较

一般就可以自己查出原因了。

同意這個說法,自己用向導先建立一個成功連接。

作者: Oraclers   发布时间: 2011-09-25