• (转载)将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;

  • 相关阅读:
    Divide Two Integers
    LRU Cache
    Max Points on a Line
    Recover Binary Search Tree
    Copy List with Random Pointer
    IEE修改最大连接数
    SQL Tuning 基础概述02
    RHEL 本地yum源配置
    Linux演示 dd测试IO
    Linux平台oracle 11g单实例 安装部署配置 快速参考
  • 原文地址:https://www.cnblogs.com/angelbd/p/3373063.html
Copyright © 2020-2023  润新知