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;

  • 相关阅读:
    STM32与FPGA通信写数据出错问题解决方法
    Altium Designer 8.0不为人知的27个技巧
    modbus详尽中文资料、软件、代码
    STM32中断与NVIC概览
    FatFs读写SD卡出现FR_NO_FILESYSTEM解决方法.
    用两个低位数的DA合成高位数的DA
    4-20mA电流转换电路分析
    C语言写的俄罗斯方块
    无源RS232转RS485(转)
    稻盛和夫写的六项精进指的是什么
  • 原文地址:https://www.cnblogs.com/angelbd/p/3373063.html
Copyright © 2011-2022 走看看