• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

(转载)将DELPHI数据库连接写进INI配置文件中

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

将DELPHI数据库连接写进INI配置文件中

procedure TDM.DataModuleCreate(Sender: TObject);
var piececonfg:Tinifile;
pathconfgstr,Providerstr,UserIDstr,
Passwordstr,DataSourceStr,DatabaseNamestr :string;
begin
pathconfgstr:= ExtractFilePath(Application.ExeName);
if pathconfgstr[length(pathconfgstr)]='/' then
begin
pathconfgstr:=pathconfgstr+'piececonfg.ini';
piececonfg:=Tinifile.Create(pathconfgstr);
end
else
begin
pathconfgstr:=pathconfgstr+'/piececonfg.ini';
piececonfg:=Tinifile.Create(pathconfgstr);
end;
if not FileExists(pathconfgstr) then
begin
application.MessageBox('配置文件不存在!','提示',mb_ok);
application.Terminate;
end;
Providerstr:=piececonfg.ReadString('DataBaseConfig','Provider','');
UserIDstr:=piececonfg.ReadString('DataBaseConfig','UserID','');
Passwordstr:=piececonfg.ReadString('DataBaseConfig','Password','');
DataSourceStr:=piececonfg.ReadString('DataBaseConfig','DataSource','');
DatabaseNamestr:=piececonfg.ReadString('DataBaseConfig','DatabaseName','');
if (Providerstr='') or (DataSourceStr='') or (DatabaseNamestr='') then
begin
application.MessageBox('数据库配置不正确,请重新配置!','提示',mb_ok);
Application.Terminate;
end;
adoconn.Close;
adoconn.ConnectionString:='';
adoconn.ConnectionString:='Provider='+Providerstr+';UserID='+UserIDstr+';
Password='+Passwordstr+';Data Source='+DataSourceStr+
Initial Catalog='+DatabaseNamestr;
try
adoconn.Connected:=true;
except
application.MessageBox('数据库配置不正确,请重新配置!','提示',mb_ok);
adoconn.Connected:=false;
application.Terminate;
end;
search:=TstringList.create;
end;

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
推荐一套免费跨平台的delphi哈希及加密算法库发布时间:2022-07-18
下一篇:
(Delphi)第一个Windows32API的窗口程序发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap