DBEXPRES组件。如何在程序设计时。动态的连接数据库
DBEXPRES组件。怎么在程序设计时。动态的连接数据库
使用EXPRESS组件,比如SQLCONNECTION时。怎么能让他动态的连接数据库。就使用ADO那样。当需要用那个数据库时。才连接!
------解决方案--------------------
//连接信息保存在ini文件中
procedure Set_SQLConnection(SQLCon:TSQLConnection;DBName:string;const Alias:string='');
var
fini:TIniFile;
se,s:string;
begin
SQLCon.Params.Clear ;
SQLCon.DriverName :='MSSQL';
SQLCon.GetDriverFunc :='getSQLDriverMSSQL';
SQLCon.LibraryName :='dbxmss30.dll';
SQLCon.VendorLib :='oledb';
s:=ExtractFilePath(Paramstr(0))+'config.ini';
Fini:=TIniFile.Create(s);
se:=DBName;
With SQLCon.Params do
begin
add('DriverName=MSSQL');
add('HostName='+Fini.readstring(se,'host',''));//服务器
add('DataBase='+DBName);
add('User_Name='+Fini.ReadString(se,'username',''));//登录用户名
add('Password='+Fini.ReadString(se,'password',''));//登录密码
add('BlobSize=0');
if Fini.ReadBool(se,'oslogin',False) then//是否为windows身份验证
add('OS Authentication=True') else
add('OS Authentication=False');
add('Prepare SQL=True');
end;
if Alias='' then//设置别名
SQLCon.ConnectionName :=DBName else
SQLCon.ConnectionName :=Alias;
SQLCon.LoginPrompt :=false;
end;
使用EXPRESS组件,比如SQLCONNECTION时。怎么能让他动态的连接数据库。就使用ADO那样。当需要用那个数据库时。才连接!
------解决方案--------------------
//连接信息保存在ini文件中
procedure Set_SQLConnection(SQLCon:TSQLConnection;DBName:string;const Alias:string='');
var
fini:TIniFile;
se,s:string;
begin
SQLCon.Params.Clear ;
SQLCon.DriverName :='MSSQL';
SQLCon.GetDriverFunc :='getSQLDriverMSSQL';
SQLCon.LibraryName :='dbxmss30.dll';
SQLCon.VendorLib :='oledb';
s:=ExtractFilePath(Paramstr(0))+'config.ini';
Fini:=TIniFile.Create(s);
se:=DBName;
With SQLCon.Params do
begin
add('DriverName=MSSQL');
add('HostName='+Fini.readstring(se,'host',''));//服务器
add('DataBase='+DBName);
add('User_Name='+Fini.ReadString(se,'username',''));//登录用户名
add('Password='+Fini.ReadString(se,'password',''));//登录密码
add('BlobSize=0');
if Fini.ReadBool(se,'oslogin',False) then//是否为windows身份验证
add('OS Authentication=True') else
add('OS Authentication=False');
add('Prepare SQL=True');
end;
if Alias='' then//设置别名
SQLCon.ConnectionName :=DBName else
SQLCon.ConnectionName :=Alias;
SQLCon.LoginPrompt :=false;
end;