CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
山寨机中的战斗机! 程序优化工程师到底对IT界有没有贡献
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  Delphi >  数据库相关

请教用ADO连接数据库路径配置问题

楼主qwaszx(半瓶醋)2005-05-27 09:44:51 在 Delphi / 数据库相关 提问

请教用ADO连接数据库时,如何通过INI类型文件来配置数据库路径?能举例说明更好? 问题点数:20、回复次数:3Top

1 楼lwjghhh(迷茫中)回复于 2005-05-27 09:48:35 得分 10

function   GetConnectionString():   widestring;  
  var  
      Servername,Database,Username,password:string;  
      LoginType:Integer;  
      IniFilePath:   String;  
  begin  
      IniFilePath   :=   Dirpatch(ExtractFileDir(Application.ExeName))+'System.ini';  
   
   
      ServerName   :=   ReadIni(IniFilePath,   'System',   'ServerName');  
      DataBase   :=   Readini(IniFilePath,   'System',   'DatabaseName');  
      UserName   :=   ReadIni(IniFilePath,   'System',   'UserName');  
      PassWord   :=   DecodeBase64(ReadIni(IniFilePath,   'System',   'Password'));  
      if   not   TryStrToInt(ReadIni(IniFilePath,   'System',   'LoginStyle'),   LoginType)   then  
          LoginType   :=1;  
   
      if   (LoginType<0)   or   (LoginType>1)   then   LoginType   :=   1;  
      Result   :=   'Provider=SQLOLEDB.1;';  
   
      if   LoginType   =   0   then  
          Result   :=   Result   +   'Integrated   Security=SSPI;Persist   Security   Info=False;'  
      else  
        begin  
          Result   :=   Result   +   'Password='+Password+';'   ;  
          Result   :=   Result   +   'Persist   Security   Info=True;User   ID='   +   Username+';';  
      end;  
   
      Result   :=   Result   +   'Initial   Catalog='   +   Database+';';  
      Result:=Result   +   'Data   Source='   +   ServerName;  
  end;Top

2 楼hellolongbin(一个人(自从扩充话题改版,再也不去灌水乐园了))回复于 2005-05-27 10:09:27 得分 10

手头上现成的  
  cfgini:=Tinifile.Create(path+'config.ini');  
  constr:='Provider=SQLOLEDB.1;Persist   Security   Info=False;User   ID=';  
          constr:=constr+cfgini.ReadString('db','username','sa');  
          constr:=constr+';PASSWORD=';  
          constr:=constr+cfgini.ReadString('db','pwd','coffee');  
          constr:=constr+';Initial   Catalog=';  
          constr:=constr+cfgini.ReadString('db','database','visa');  
          constr:=constr+';Data   Source='+cfgini.ReadString('db','datasource','renant');  
          Form3.ADOConnection1.Connected:=false;  
          Form3.ADOConnection1.LoginPrompt  
          Form3.ADOConnection1.ConnectionString:=constr;  
                  Form3.ADOConnection1.Connected:=True;  
                  Form3.ADOQuery1.Connection:   .SQL.Clear;  
                  sqlstr:='select   passwd   from   login   where   userid='''+Edit1.Text+'''';  
                  Form3.ADOQuery1.SQL.Add(sqlstr);  
                  Form3.ADOQuery1.Open;Top

3 楼Kshape(C/C++初学者~~~~)回复于 2005-05-27 10:53:00 得分 0

把密码用户名与服务器名字保存到ini中  
  连接失败则读取并且重新写入就可以了  
  具体查看ini操作  
  宝典上有介绍的Top

相关问题

  • installshield4.0配置本地数据库的路径问题
  • 我用ADO连接数据库,怎么用相对路径。
  • ado链接数据库的相对路径问题.
  • ADO连接数据库路径怎么自动设置?
  • 使用ado连接数据库如何使用相对路径??
  • 如何在weblogic中配置类路径,我要连接sql server2000数据库。
  • 数据库ado
  • 数据库路径问题
  • 用ADO连数据库时怎样用相对路径?大家帮帮忙,急!
  • 用ADO连数据库时怎样用相对路径?大家帮帮忙,急!

关键词

  • 数据库
  • 连接
  • security
  • database
  • db
  • constr
  • inifilepath
  • cfgini
  • logintype
  • readini

得分解答快速导航

  • 帖主:qwaszx
  • lwjghhh
  • hellolongbin

相关链接

  • Delphi类图书
  • Delphi类源码下载
  • Delphi控件下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo