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;

  • 相关阅读:
    Redis网络连接库剖析
    如何下载和安装pywin32
    Python游戏开发入门:pygame事件处理机制
    python常见错误
    波特率与比特率
    __gcd最大公约数
    动态规划算法之矩阵连乘问题
    二分插入排序+二分搜索
    office 总结
    javaWeb总结
  • 原文地址:https://www.cnblogs.com/angelbd/p/3373063.html
Copyright © 2011-2022 走看看