adoconnection的属性connectionstring的设置??(100分)

  • 主题发起人 主题发起人 day_and_day
  • 开始时间 开始时间
D

day_and_day

Unregistered / Unconfirmed
GUEST, unregistred user!
adoconnection的属性connectionstring的设置??[:(!]
 
function CreateDBStr(DBServer,DBName,User,PWD:string):String;
{功能:根据参数产生连接数据库的ADO参数}
begin
Result := 'Provider=SQLOLEDB.1;Password='+PWD+';Persist Security Info=True;User ID='+
User+';Initial Catalog='+DBName+';Data Source='+DBServer;
end;
PWD=密码
User=数据库用户
DBname=数据库名
DBServer=数据库服务器
 
To hupen:
我想把它作成一个*.ini文件,再在程序中调用,该怎么做??
 
直接存放到注册表中更方便,免费用一个INI文件.
注册表的读入或写出你自己找一找就可以了.
 
用UDL文件连接更好用!
如果要用Ini的话,就是TIniFile的操作,文件里各项写你的连接设置如用户名密码数据库
等,读出来动态生成Connectionstring。
 
to:hbezwwl and GanQuan
写点代码啊???
 
S:=adoconnection.Connectionstring;//这个你自己在程序中第一次运行时可以让用户定义.

拷贝Pipi的旧帖
首先:uses registry;
var
r:TRegistry
r:=Tregistry.Create;
r.RootKey:=HKEY_LOCAL_MACHINE、HKEY_CURRENT_USER 之类
r.OpenKey('Software/microsoft'之类, true);
然后就可以 r.ReadString 、 r.ReadInteger、r.WriteString 、 r.WriteInteger 之类
r.Free;

你查查旧帖,N多。 查讯关键字:注册表
 
来晚了...:(
注册表是好办法.
 
同意楼上
 
如果用Ini的话,就这样。
connect.ini文件格式
[connection]
UserId=YourId
Password=YourPassword
Database=YourDatabase
DataServer=YoureDataServer
......
程序
uses Inifiles;
...
var
IniFile: TIniFile;
UserId,Password: String;
begin
....
IniFile := TIniFile.Create(YourDir + '/Connect.ini');
UserId := InIFile.ReadString('Connection','UserId','');
Password := IniFile.ReadString('Connection','UserPassword','');
.....
//根据取值生成Connectionstring。
。。。。。
end;
IniFile的操作看看帮助,或者查查旧帖。就是写Readstring,readinteger...WriteString
wirterinteger之类的操作,很简单。

 
楼上的楼上的答案不错[:)]
 
贴我自己的代码吧,反正不费事
下面函数根据INI文件生成连接字符串,不依赖于某特定ADO连接,只需要你的INI文件的属性正确
先附上一个MSSQL连接INI例子//其实其他离子你可以先用TADOCONNECTION设计态生成一个,依次类推
------------------------------------common.ini
[ADO]
Provider=SQLOLEDB.1
Password=test
Persist Security Info=True
User ID=sa
Initial Catalog=db //数据库名
Data Source=155.155.71.100 //数据库机器名
-------------------------------------------------------------
function GetDataBaseInfo:string; //生成连接字符串
var lDataInfo:TIniFile;
lStrings:TStrings;
lReadIndex:integer;
begin
//读取配置的INI文件从而生成DATABASE的连接
lDataInfo:=TInifile.Create('../etc/Common.ini');
lStrings:= TStringList.Create;
try
Try
lDataInfo.ReadSectionValues('ADO',lStrings);
except
GP_ShowAccess('读取系统连接配置文件失败!');
End;
for lReadIndex:=0 to lStrings.Count-1 do
begin
if pos('Password=',lStrings[lReadIndex])=1 then
Result:=Result+'Password='+GF_NewStrToStr(lDataInfo.ReadString('ADO','password',''))+';'
//这里是自己写了段把密码加密和反加密的函数;一般你总不希望任何人一看你的INI就知道数据库密码了吧?!
Else
Result:=Result+lStrings[lReadIndex]+';';
end;
finally
lDataInfo.free;
lStrings.Free;
end;
end;
 
后退
顶部