用dbexpress控件中的sqlconnection连接interbase数据库的动态连接参数设置

zhangpuqing 2008-02-22 08:13:27
用dbexpress控件中的sqlconnection连接interbase数据库的动态连接参数设置
目前遇着很奇怪的问题,设置如下
inif.Create(getcurrentdir+'\config.ini');
sqlconnection1.Connected:=false;
sqlconnection1.Params.Clear;

try
sqlconnection1.Params.Append('drivername='+inif.ReadString('zblsjxc','drivername',''));
sqlconnection1.Params.append('driverunit='+inif.readstring('zblsjxc','driverunit',''));
sqlconnection1.Params.append('DriverPackageLoader='+inif.readstring('zblsjxc','DriverPackageLoader',''));
sqlconnection1.Params.append('DriverAssemblyLoader='+inif.readstring('zblsjxc','DriverAssemblyLoader',''));
sqlconnection1.Params.append('MetaDataPackageLoader='+inif.readstring('zblsjxc','MetaDataPackageLoader',''));
sqlconnection1.Params.append('MetaDataAssemblyLoader='+inif.readstring('zblsjxc','MetaDataAssemblyLoader',''));
sqlconnection1.Params.append('BlobSize='+inif.readstring('zblsjxc','BlobSize',''));
sqlconnection1.Params.append('CommitRetain='+inif.readstring('zblsjxc','CommitRetain',''));
sqlconnection1.Params.append('Database='+inif.ReadString('database','databaseservername','')+':'+inif.ReadString('database','databasename',''));
sqlconnection1.Params.append('ErrorResourceFile='+inif.ReadString('zblsjxc','ErrorResourceFile',''));
sqlconnection1.Params.append('LocaleCode='+inif.ReadString('zblsjxc','LocaleCode',''));
sqlconnection1.Params.append('Password='+inif.ReadString('zblsjxc','Password',''));
sqlconnection1.Params.append('RoleName='+inif.ReadString('zblsjxc','RoleName',''));
sqlconnection1.Params.append('ServerCharSet='+inif.ReadString('zblsjxc','ServerCharSet',''));
sqlconnection1.Params.append('SQLDialect='+inif.ReadString('zblsjxc','SQLDialect',''));
sqlconnection1.Params.append('Interbase TransIsolation='+inif.ReadString('zblsjxc','Interbase TransIsolation',''));
sqlconnection1.Params.append('User_Name='+inif.ReadString('zblsjxc','User_Name',''));
sqlconnection1.Params.append('WaitOnLocks='+inif.ReadString('zblsjxc','WaitOnLocks',''));
sqlconnection1.Params.append('Trim Char='+inif.ReadString('zblsjxc','Trim Char',''));
finally
inif.Free;
end;
编译后运行,在进入界面时会报错,但进入界面后,能够查询到数据库里的资料.WHY!!!!
...全文
182 点赞 收藏 5
写回复
5 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
chmily8888 2008-03-05
参数是写在配置文件下当然要打包了
回复
zhangpuqing 2008-03-04
报错的原因找到了是因为没有指定CONNECTIONNAME的原因.
然后我想问一下在参数里有Con.Params.Add('DriverName=MySql');这句话,那么如果我程序在发布的时,是不是需要把dbxdrivers.ini这个文件也跟着打包呢.
回复
chmily8888 2008-02-29
function CreateCon(HostName,DataBase,UserName,PassWord:String):TSQLConnection;
var
Con:TSQLConnection;
begin
Con := TSQLConnection.Create(nil);
Con.Params.Clear;
Con.Params.Add('DriverName=MySql');
Con.Params.Add('HostName='+HostName);
Con.Params.Add('DataBase='+DataBase);
Con.Params.Add('User_Name='+UserName);
Con.Params.Add('Password='+PassWord);

Con.ConnectionName := 'MySQLConnection';
Con.DriverName := 'MySQL';
Con.GetDriverFunc := 'getSQLDriverMYSQL';
Con.LibraryName := 'dbxmys30.dll';
Con.VendorLib := 'libmysql.dll';
Con.LoginPrompt := false;

Result := Con;
end;
回复
zhangpuqing 2008-02-26
楼上的好像不行呀,那样的话也有提示报错的.
回复
ydlchina 2008-02-23
干嘛要那么麻烦
SQLConnection.Connected:=False;
SQLConnection.ConnectionName:='SQLServer';
SQLConnection.DriverName:='SQLServer';
SQLConnection.Params.Values['Database']:=dbname;
SQLConnection.Params.Values['HostName']:=computer;
SQLConnection.Params.Values['User_Name']:='sa';
SQLConnection.Params.Values['Password']:='';
SQLConnection.Connected:=True;
回复
发帖
数据库相关
创建于2007-08-02

2451

社区成员

Delphi 数据库相关
申请成为版主
帖子事件
创建了帖子
2008-02-22 08:13
社区公告
暂无公告