好学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

delphi7从入门到精通之四
  Delphi编辑器在表面上,对IDE的第7个版本来说Delphi的编辑器看来似乎没有改变许多。然而,在幕后,它是一个全新的工具。除…
  • 好学考试H5触屏版开放内测
  • 好学触屏公众号虎力全开、杨帆起航!