好学IT学院:IT信息技术分享交流平台
标签:Delphi  来源:www.swgame.cn  作者:系统维护员  发布时间:2008-06-13  ★★★加入收藏〗〖手机版
摘要:要将DELPHI数据库连接写进INI配置文件中,参数代码如下:DataBase.pas++++++++++++++++++++++++++++++++++++++++++++procedure TDM.DataModuleCreate(Se……

要将DELPHI数据库连接写进INI配置文件中,参数代码如下:

DataBase.pas
++++++++++++++++++++++++++++++++++++++++++++

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;

piececonfg.ini
++++++++++++++++++++++++++++++++++++++++++++

[DataBaseConfig]
   Provider=SQLOLEDB.1
   UserID=sa
   Password=sa
   DataSource=192.168.1.1
   DatabaseName=mjj

Delphi.NET多层应用系统开发技术研讨
  从上个星期就开始有朋友问我为什么很久没有更新Blog了,其实我想我写Blog已经很勤快了,这次10多天没有更新Blog想当然是我又…
  • 好学考试H5触屏版开放内测
  • 好学触屏公众号虎力全开、杨帆起航!