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