PDA

View Full Version : connection Delphi and Crystal Reports



Srdjan
15-Sep-2005, 06:09 AM
Hi everyone

This problem is a bit confusing for me
Few weeks ago, we've started to use Crystal Report 11

For procedure testing, we MUST change
database name and server name,
To avoid recompile all reports, we are changing connect properties
from application with following code:

Crpe1.ReportName := OpenDialog1.FileName;
Crpe1.DiscardSavedData;
Crpe1.Connect.ServerName := 'SERVER';
Crpe1.Connect.DatabaseName := 'Sales';
Crpe1.Connect.UserID := 'Marta';
...
..
. etc

Code above does not work with MS SQL 2000,
Again, results are from original database

On the Internet, I couldn't find any text about this problem

Is there solutions for this

Thanx
Srdjan

Pieter van Dieren
16-Sep-2005, 06:53 AM
I guess you'll get a better response if you ask this question in a Delphi
newsgroup....

Ole Kirkholt
14-Oct-2005, 05:27 AM
mvh ole
"Srdjan" <p@p.com> skrev i en meddelelse
news:tglii1lc89pdt1ngqm4h07hgpv23an6ida@4ax.com...
> Hi everyone
>
> This problem is a bit confusing for me
> Few weeks ago, we've started to use Crystal Report 11
>
> For procedure testing, we MUST change
> database name and server name,
> To avoid recompile all reports, we are changing connect properties
> from application with following code:
>
> Crpe1.ReportName := OpenDialog1.FileName;
> Crpe1.DiscardSavedData;
> Crpe1.Connect.ServerName := 'SERVER';
> Crpe1.Connect.DatabaseName := 'Sales';
> Crpe1.Connect.UserID := 'Marta';
> ...
> ..
> . etc
>
> Code above does not work with MS SQL 2000,
> Again, results are from original database
>
> On the Internet, I couldn't find any text about this problem
>
> Is there solutions for this
>
> Thanx
> Srdjan

Yes, you must remove the databasename from the sql-string in the report:


..
..
crpe.Clear;
Crpe.ReportName:= GlobalIni.GetStringParm('reports','path')+'\'+Rap;
Crpe.Connect.ServerName:= DbServerName;
Crpe.connect.DatabaseName:=DbDatabaseName;
Crpe.Connect.UserID:= dbUserName;
Crpe.connect.Password:=dbPassword;


Result := Crpe.Connect.Test;
crpe.SQL.Retrieve;
StrRemoveDbName(crpe.SQL.Query);

..
..
..
..
..
function TDbm.StrRemoveDbName(sql: tstrings): Boolean;
var
cnt: integer;
Regex: TPerlRegEx;
begin
Regex := TPerlRegEx.Create(nil);
Regex.RegEx := '"?[-_0-9a-z]*"?\."?dbo"?';
Regex.Options := [preCaseless];
Regex.Replacement := '"dbo"';

for cnt := 0 to sql.Count -1 do
begin
Regex.Subject := sql.Strings[cnt];
Regex.ReplaceAll;
sql.Strings[cnt] := Regex.Subject
end;
Result := true;
regEx.Free;
end;

Best regards

Ole