最近用Inno做一个安装包,其中有一部分是安装数据库,考虑减少安装包的通用性,我用ado访问数据库。安装数据库中需要判断是否已有对应版本的数据库,首先:
use [master]
go
select [name] from sysdatabases
go
获取所有数据库,ado不支持"go",进行拆分发送,然后检测每个数据库是否符合软件要求,整体代码如下:
conn.Open(connstr);
conn.Execute('use [master]');
rs:= CreateOleObject('ADODB.RecordSet');
rs2:= CreateOleObject('ADODB.RecordSet');
rs.Open('select [name] from sysdatabases',conn);
while not rs.EOF do
begin
conn.Execute('use ['+rs.Fields(0).Value+']');
rs2.Open(sql,conn);
if (rs2.Fields(0).Value=1) then
begin
databaselist.Items.Add(rs.Fields(0).Value);
flag:=true;
end
rs2.close;
rs.MoveNext;
end
conn.close;
结果rs2返回的结果错误,只有当符合要求的数据库位于最后一个时才会检测成功,在inno垃圾的调试环境测试了好久,最后还是拿到vb中测试最终发现只要将
rs.Open('select [name] from sysdatabases',conn);
改为
rs.Open('select [name] from sysdatabases',connstr);
问题就可以解决,可能ado在两个结果集使用同一个连接时相互会发生影响,可是具体的原因是什么呢?
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)