初学者求一个通过INI访问SQL的DEMO(50分)

  • 主题发起人 主题发起人 yzwork
  • 开始时间 开始时间
Y

yzwork

Unregistered / Unconfirmed
GUEST, unregistred user!
我是一个DELPHI初学者,现在求一个通过INI访问SQL的DEMO<br><br>哪位高手可以指教下??<br><br>我照着书本上的DEMO试了好几次都不能稳定的实现........
 
INI内容<br><br>服务器名<br>登陆用户<br>登陆密码<br>数据名
 
来骗点分。[:D]<br><br>[MSSQLOptions]<br>ServerName="192.168.1.254"<br>UserID="sa"<br>Password="123"<br>DatabaseName="DemoDB"<br><br>代码<br>uses<br>&nbsp; IniFiles;<br><br>function ReadConnectionStringFromIni(FileName:string):string;<br>const<br>&nbsp; TemplateConnStr='Provider=SQLOLEDB.1;Persist Security Info=False;User ID=%s;PWD=%s;Initial Catalog=%s;Data Source=%s';<br>var<br>&nbsp; IniReader:TIniFile; &nbsp;<br>begin<br>&nbsp; IniReader:=TIniFile.Create(FileName);<br>&nbsp; with IniReader do<br>&nbsp; try<br>&nbsp; Result:=Format(TemplateConnStr,<br>&nbsp; &nbsp; &nbsp;[ReadString('MSSQLOptions','UserId',''),<br>&nbsp; &nbsp; &nbsp;ReadString('MSSQLOptions','Password',''),<br>&nbsp; &nbsp; &nbsp;ReadString('MSSQLOptions','DatabaseName',''),<br>&nbsp; &nbsp; &nbsp;ReadString('MSSQLOptions','ServerName','')]);<br>&nbsp; finally<br>&nbsp; &nbsp; Free;<br>&nbsp; end;<br>end;<br>用这个返回的连接字符串做ADOConnection.ConnectionString就可以了。
 
后退
顶部