同意! s:='Provider=SQLOLEDB.1;Password='+UserPass+';Persist Security Info=True;'+ 'User ID='+UserName+';Initial Catalog='+DataBaseName+';'+ ' Data Source='+ServerName+';';
s:='Provider=SQLOLEDB.1;Password='+UserPass+';Persist Security Info=True;'+ 'User ID='+UserName+';Initial Catalog='+DataBaseName+';'+ ' Data Source='+ServerName+';';
//连接数据库 function tdmodule.connectedDB(var msg:string):boolean; begin if ADOConnection1.Connected then Result:=True else begin try ADOConnection1.ConnectionString:=getStr; adoconnection1.LoginPrompt:=false; adoquery1.Connection:=ADOConnection1; if length(trim(ADOConnection1.ConnectionString))=0 then begin msg:='错误的连接字符串!'; Result:=False; end else begin ADOConnection1.Connected:=True; Result:=True; end; except msg:='无法建立数据库连接!'; Result:=False; end; end; end;//得到连接字符串 function tdmodule.getstr():string; var path:String; tmp:TStrings; counter:Integer; myIniFile:Tinifile;//配置文件 begin tmp:=TStringList.Create; try path:=ExtractFilePath(Application.Exename); myIniFile:=TiniFile.Create(path+'database.ini'); myIniFile.ReadSectionValues('database',tmp); Result:=' '; for counter:=0 to tmp.Count-1 do Result:=Result+tmp.Strings[counter]; finally tmp.Free; end; end; 两个函数读取database.ini并且用adoconnection连接的
s:='Provider=SQLOLEDB.1;Password='+UserPass+';Persist Security Info=True;'+
'User ID='+UserName+';Initial Catalog='+DataBaseName+';'+
' Data Source='+ServerName+';';
'User ID='+UserName+';Initial Catalog='+DataBaseName+';'+
' Data Source='+ServerName+';';
function tdmodule.connectedDB(var msg:string):boolean;
begin
if ADOConnection1.Connected then
Result:=True
else
begin
try
ADOConnection1.ConnectionString:=getStr;
adoconnection1.LoginPrompt:=false;
adoquery1.Connection:=ADOConnection1;
if length(trim(ADOConnection1.ConnectionString))=0 then
begin
msg:='错误的连接字符串!';
Result:=False;
end
else
begin
ADOConnection1.Connected:=True;
Result:=True;
end;
except
msg:='无法建立数据库连接!';
Result:=False;
end;
end;
end;//得到连接字符串
function tdmodule.getstr():string;
var path:String;
tmp:TStrings;
counter:Integer;
myIniFile:Tinifile;//配置文件
begin
tmp:=TStringList.Create;
try
path:=ExtractFilePath(Application.Exename);
myIniFile:=TiniFile.Create(path+'database.ini');
myIniFile.ReadSectionValues('database',tmp);
Result:=' ';
for counter:=0 to tmp.Count-1 do
Result:=Result+tmp.Strings[counter];
finally
tmp.Free;
end;
end;
两个函数读取database.ini并且用adoconnection连接的