首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

deliph连接数据库解决办法

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

deliph连接数据库
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.

[解决办法]
用什么 ADO 连数据库啊。你下个组件, UniDac 支持多种数据库,无需配 ODBC

下载地址
http://download.csdn.net/detail/netcreate/3517299

[解决办法]
先用adoconnection,adoquery连接数据库。首先用adoconnection连接数据库,然后设置adoquery的connection属性为ADOConnection1,然后再写入下列代码
adoquery1.close;
adoquery1.sql.clear;
adoquery1.sql.add('select * from 表1');
adoquery1.open;

[解决办法]
用 ADO 你先双击 ADOCONNECT 然后看看能不能直接连上数据库.


可以的话 把 connect string 复制出来

你这个 Connect String 是弄得一塌糊涂乱七八糟..


每一段都分开 然后用整合一块 又整洁 又不容易出错.
[解决办法]

Delphi(Pascal) code
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;

[解决办法]
AdoConnection1.Connected := false;
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;
还有一些属性设置是直接在界面上 并没有用代码表示
[解决办法]
兩個辦法 靜態連接 動態連接!

热点排行