| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 4650 人关注过本帖
标题:动态连接SQL数据库
只看楼主 加入收藏
shede
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2005-3-6
收藏
得分:0 
我使用动态参数连接的时候为什么说错误的呢?我跟前面的设置方法一样的啊?在调试的时候给出错误,我在调试的时候还没有写其他的窗口代码?那个告述我是什么原因?谢谢!
2005-03-06 11:25
王万林
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2013-8-20
收藏
得分:0 
unit Uregister;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons,inifiles, ExtCtrls;

type
  TFregister = class(TForm)
    Image1: TImage;
    EWMIS_ServerName: TEdit;
    EWMIS_loginName: TEdit;
    EWMIS_PWD: TEdit;
    EWMIS_DbsName: TEdit;
    EYH_ServerName: TEdit;
    EYH_loginName: TEdit;
    EYH_PWD: TEdit;
    EYH_DbsName: TEdit;
    Button1: TButton;
    Button2: TButton;
    Panel1: TPanel;
    Panel2: TPanel;
    Button3: TButton;
    Button5: TButton;
    procedure FormShow(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure EWMIS_ServerNameChange(Sender: TObject);
    procedure EWMIS_loginNameChange(Sender: TObject);
    procedure EWMIS_PWDChange(Sender: TObject);
    procedure EWMIS_DbsNameChange(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Fregister: TFregister;

implementation

uses dataMU, ClassesU;

{$R *.dfm}

procedure TFregister.FormShow(Sender: TObject);
Var
myinifile:Tinifile;
begin
myinifile:=Tinifile.create(ExtractFilepath(paramstr(0))+'WmisYH.ini');

EWMIS_ServerName.text := myinifile.ReadString('县级登录参数','服务器名','(local)');
EWMIS_LoginName.text := myinifile.ReadString('县级登录参数','用户名','sa');
EWMIS_PWD.text := myinifile.ReadString('县级登录参数','密码','');
EWMIS_DbsName.text := myinifile.ReadString('县级登录参数','数据库名','pis_base_xj');
EYH_ServerName.text := myinifile.ReadString('业务登录参数','服务器名','(local)');
EYH_LoginName.text := myinifile.ReadString('业务登录参数','用户名','sa');
EYH_PWD.text := myinifile.ReadString('业务登录参数','密码','');
EYH_DbsName.text := myinifile.ReadString('业务登录参数','数据库名','pis_base_YH') ;

end;

procedure TFregister.BitBtn1Click(Sender: TObject);
Var
myinifile:Tinifile;
begin
myinifile:=Tinifile.create(ExtractFilepath(paramstr(0))+'WmisYH.ini');

myinifile.WriteString('县级登录参数','服务器名',EWMIS_ServerName.text);
myinifile.WriteString('县级登录参数','用户名',EWMIS_LoginName.text);
myinifile.WriteString('县级登录参数','密码',EWMIS_PWD.text);
myinifile.WriteString('县级登录参数','数据库名',EWMIS_DbsName.text);
myinifile.WriteString('业务登录参数','服务器名',EYH_ServerName.text);
myinifile.WriteString('业务登录参数','用户名',EYH_LoginName.text);
myinifile.WriteString('业务登录参数','密码',EYH_PWD.text);
myinifile.WriteString('业务登录参数','数据库名',EYH_DbsName.text) ;


end;
procedure TFregister.BitBtn2Click(Sender: TObject);

begin

close;

end;

procedure TFregister.Button1Click(Sender: TObject);
Var
WMISconnstring:string;
begin
WMISconnstring:='Provider=SQLOLEDB.1;Password=' + EWMIS_PWD.Text +
';Persist Security Info=True;User ID=' + EWMIS_loginName.Text +
';Initial Catalog=' + EWMIS_DbsName.Text  + ';Data Source=' + EWMIS_ServerName.Text ;
DataM.ADOConn_base.ConnectionString:=WMISconnstring;
try
datam.ADOConn_base.Connected:=true;
MessageBox(Handle, 'PIS基础数据库连接成功!', '信息', MB_ICONASTERISK);
Button3.Enabled:=true;
except
MessageBox(Handle, 'PIS基础数据库连接失败!', '信息', MB_ICONASTERISK);
Button3.Enabled:=false;
end;
end;
procedure TFregister.Button2Click(Sender: TObject);
Var
YHconnstring:string;
begin
YHconnstring:='Provider=SQLOLEDB.1;Password=' + EYH_PWD.Text+
';Persist Security Info=True;User ID=' + EYH_loginName.Text  +
';Initial Catalog=' + EYH_DbsName.Text  + ';Data Source=' + EYH_ServerName.Text ;
dataM.ADOCONn_YH.ConnectionString:=YHconnstring;
try
dataM.ADOCONn_YH.Connected:=true;
MessageBox(Handle, '业务数据库连接成功!', '信息', MB_ICONASTERISK);
Button5.Enabled:=true;
except
MessageBox(Handle, '业务数据库连接失败!', '信息', MB_ICONASTERISK);
Button5.Enabled:=false;
end;
end;

procedure TFregister.Button3Click(Sender: TObject);
Var
myinifile:Tinifile;
begin
myinifile:=Tinifile.create(ExtractFilepath(paramstr(0))+'WmisYH.ini');

myinifile.WriteString('县级登录参数','服务器名',EWMIS_ServerName.text);
myinifile.WriteString('县级登录参数','用户名',EWMIS_LoginName.text);
myinifile.WriteString('县级登录参数','密码',EWMIS_PWD.text);
myinifile.WriteString('县级登录参数','数据库名',EWMIS_DbsName.text);
myinifile.Destroy;
end;
procedure TFregister.Button5Click(Sender: TObject);
Var
myinifile:Tinifile;
begin
myinifile:=Tinifile.create(ExtractFilepath(paramstr(0))+'WmisYH.ini');
myinifile.WriteString('业务登录参数','用户名',EYH_LoginName.text);
myinifile.WriteString('业务登录参数','密码',EYH_PWD.text);
myinifile.WriteString('业务登录参数','数据库名',EYH_DbsName.text) ;
myinifile.Destroy;
end;
procedure TFregister.EWMIS_ServerNameChange(Sender: TObject);
begin
datam.ADOConn_base.Connected:=false;
end;

procedure TFregister.EWMIS_loginNameChange(Sender: TObject);
begin
 datam.ADOConn_base.Connected:=false;
end;

procedure TFregister.EWMIS_PWDChange(Sender: TObject);
begin
 datam.ADOConn_base.Connected:=false;
end;

procedure TFregister.EWMIS_DbsNameChange(Sender: TObject);
begin
 datam.ADOConn_base.Connected:=false;
end;

end.
2013-08-20 15:29
王万林
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2013-8-20
收藏
得分:0 
unit dataMU;

interface

uses
  SysUtils, Classes, DB, ADODB;

type
  TDataM = class(TDataModule)
    ADOConn_base: TADOConnection;
    ADOConn_yh: TADOConnection;
    procedure DataModuleCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  DataM: TDataM;

implementation

uses ClassesU,inifiles;

{$R *.dfm}

procedure TDataM.DataModuleCreate(Sender: TObject);
Var
WMISconnstring:string;
YHconnstring:string;
EWMIS:TEsys;
EYH:TEsys;
myinifile:Tinifile;
begin
EWMIS:=TEsys.create;
EYH:=Tesys.create;
myinifile:=Tinifile.create(ExtractFilepath(paramstr(0))+'WmisYH.ini');
EWMIS.ServerName:= myinifile.ReadString('县级登录参数','服务器名','(local)');
EWMIS.useName:= myinifile.ReadString('县级登录参数','用户名','sa');
EWMIS.PWD := myinifile.ReadString('县级登录参数','密码','');
EWMIS.DbsName:= myinifile.ReadString('县级登录参数','数据库名','pis_base_xj');
EYH.ServerName:= myinifile.ReadString('业务登录参数','服务器名','(local)');
EYH.useName:= myinifile.ReadString('业务登录参数','用户名','sa');
EYH.PWD:= myinifile.ReadString('业务登录参数','密码','');
EYH.DbsName:= myinifile.ReadString('业务登录参数','数据库名','pis_base_YH') ;
WMISconnstring:='Provider=SQLOLEDB.1;Password=' + EWMIS.PWD +
';Persist Security Info=True;User ID=' + EWMIS.useName +
';Initial Catalog=' + EWMIS.DbsName + ';Data Source=' + EWMIS.ServerName;
ADOCONN_base.ConnectionString:=WMISconnstring;
YHconnstring:='Provider=SQLOLEDB.1;Password=' + EYH.PWD+
';Persist Security Info=True;User ID=' + EYH.useName +
';Initial Catalog=' + EYH.DbsName + ';Data Source=' + EYH.ServerName;
ADOCONN_YH.ConnectionString:=YHconnstring;
end;

end.
2013-08-20 15:33
王万林
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2013-8-20
收藏
得分:0 
unit ClassesU;

interface
type
  TOperator=class
     xzcode:string;
     id:integer;
     OperatorName:string;
     pwd:string;
     OperatorLevel:string;
end;

type
  TEsys=class
     ServerName:string;
     useName:string;
     PWD:string;
      DbsName:string;
End;
implementation

end.
2013-08-20 15:33
快速回复:动态连接SQL数据库
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021416 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved