在我的 (Win32) 应用程序中,我正在显示 Crystal Reports。
我在运行时设置了登录信息。然而,Crystal 决定根据报表的连接方式,使用几个不同的名称来引用数据库名称。例如,如果报表通过 ODBC 连接进行连接,则称为“数据源”,但如果直接连接,则称为“服务器”。
当然,直到运行时我们才知道将调用哪个报告。
目前,我通过吞下异常并尝试替代方法来解决该问题,如下所示:
procedure TCrystalReporter11.SetLoginInfo(const username, password,
server : string);
var
i : integer;
begin
//set user name and password
//crystal only accepts these values if they are CONST params
for i := 1 to FRpt.Database.Tables.Count do begin
FRpt.Database.Tables[i].ConnectionProperties.Item['User ID'] := username;
FRpt.Database.Tables[i].ConnectionProperties.Item['Password'] := password;
try
{
Some reports use direct connections, and others use an ODBC Data Source.
Crystal XI uses a different label to refer to the database name in each
method.
I don't know how to determine in advance which method is being used, so:
First, we try the direct connection.
If that fails, we try the "data source" method.
Reference: "Crystal Reports XI Technical Reference", pages 41 thru 46;
"Common ConnectionProperties"
}
FRpt.Database.Tables[i].ConnectionProperties.Item['Server'] := server;
except on E: Exception do
FRpt.Database.Tables[i].ConnectionProperties.Item['Data Source'] := server;
end;
end;
end;
理想情况下,我想说的是:
case FRpt.Database.Tables[i].ConnectionProperties.ConnectMethod of
crymethod_ODBC : sIdx := 'Data Source';
crymethod_Direct : sIdx := 'Server';
...other methods...
end; //case
FRpt.Database.Tables[i].ConnectionProperties.Item[sIdx] := server;
所以我的问题是:
在登录之前,如何在运行时确定 Crystal XI 报表的连接方法?
背景信息:
- 我使用的是 Delphi 2007
- 我正在显示 使用 ActiveX 的报告 图书馆,很麻烦 困难、愚蠢、不可避免 (see this post)。
- 报告采用 Crystal XI SP4
- 为了讨论方便,我们假设报告都是针对 Oracle 10g 数据库
- 我的开发计算机使用的是 Windows Vista,大多数用户使用的是 XP。
非常感谢您提供的任何帮助。
最佳答案
在 Tables[i].ConnectionProperties 中查找 DSN 项。非 ODBC 不会有它,据我所知,ODBC 总是应该有。
关于delphi - 在登录之前,如何在运行时确定 Crystal XI 报表的连接方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/389113/