zoukankan      html  css  js  c++  java
  • (转载)将DELPHI数据库连接写进INI配置文件中

    将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;

  • 相关阅读:
    ubuntu新的配置
    今天下午鼓捣android-studio的一些经验
    Sublime Text 3
    学Web前端开发,选择培训学校是关键--青岛思途
    让HTML5游戏来的更猛烈些吧!--青岛思途
    Java架构师和开发者实用工具推荐
    Java培训班4个月有用吗?
    Java培训机构如何选择才能避免被骗?
    Java跟JavaScript两者间的关系和区别
    浅谈java中的四个核心概念--思途青岛
  • 原文地址:https://www.cnblogs.com/angelbd/p/3373063.html
Copyright © 2011-2022 走看看