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;

  • 相关阅读:
    .Net中通过反射技术的应用插件程序的开发入门
    html超链接button
    WCF 跨域 Http绑定
    在ASP.NET MVC中修改默认代码生成/支架模板
    使用Lambda表达式重构委托
    使用公用表表达式(CTE)简化嵌套SQL
    WCF同域动态绑定服务地址
    WCF 跨域TCP绑定
    Silverlight 基础收集
    WCF服务控制台托管方法(不使用配置文件)
  • 原文地址:https://www.cnblogs.com/angelbd/p/3373063.html
Copyright © 2011-2022 走看看