deliph连接数据库老是说连接属性错误,晕死了,求大师解决代码如下:
unit Unit1;interfaceuses
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.
unit Unit1;interfaceuses
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.
http://download.csdn.net/detail/netcreate/3517299
adoquery1.close;
adoquery1.sql.clear;
adoquery1.sql.add('select * from 表1');
adoquery1.open;
可以的话 把 connect string 复制出来你这个 Connect String 是弄得一塌糊涂乱七八糟..
每一段都分开 然后用整合一块 又整洁 又不容易出错.
function TForm1.OpenADOConn: boolean;
begin
result:=true;
try with ADoconnect1 do
begin
Connected:= false;
Provider:= 'SQLOLEDB.1'; Properties['Data Source'].Value:= '172.16.228.1' ; //服务器名
Properties['Initial Catalog'].Value:= 'ATT2000' ; //表名
Properties['User ID'].Value:= 'sa'; //用户名
Properties['password'].Value:= '123456'; //密码
LoginPrompt:= false;
try
Connected:= true;
except
begin
Application.MessageBox('无法连结远程数据库!'
,'注意', MB_OK);
result:=False;
end;
end;
end;
finally end;
end;
s := 'Provider=MSDAORA.1;Password=GRIP_TEST;User ID=GRIP_TEST;Data Source=ZAIMUBERP1;Persist Security Info=True';
AdoConnection1.ConnectionString :=s;
AdoConnection1.LoginPrompt := False;
AdoConnection1.Connected := true;
AdoTable1.Active := false;
AdoTable1.Connection := AdoConnection1;
AdoTable1.TableName :='KA_BASE';
vservername.Setfocus;
还有一些属性设置是直接在界面上 并没有用代码表示