SAP Knowledge Base Article - Public

1313185 - Delphi VCL Connecting to SQL Server 2005 database

Symptom

  • Report made against SQL Server 2000 database.
  • At runtime changing to SQL 2005, get error: Unable to connect incorrect logon parameters

Resolution

Use the following code example:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, UCrpeClasses, UCrpe32, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Crpe1: TCrpe;
    Label1: TLabel;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  cnt: Integer;
  cntsub: Integer;
  cntin: Integer;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);

begin
Crpe1.ReportName:='C:\ReportEMP.rpt';

{passing logon information for Main Report}

for cnt:= 0 to (Crpe1.Tables.Count - 1) do
begin
Crpe1.Tables[cnt].ConnectBuffer := 'Provider=SQLOLEDB.1;Password=sa;Persist Security Info=True;User ID=sa;Initial Catalog=Northwind;Data Source=10.130.41.80';
end;

{passing logon information to subreports}

for cntsub:= 0 to (Crpe1.Subreports.Count - 1) do
begin
  for cntin:=0 to (Crpe1.Subreports[cntsub].Tables.Count - 1) do
  begin
    Crpe1.Subreports[cntsub].Tables[cntin].ConnectBuffer:='Provider=SQLOLEDB.1;Password=sa;Persist Security Info=True;User ID=sa;Initial Catalog=Northwind;Data Source=10.130.41.80';
  end;
end;
Crpe1.Execute;
end;
end. 

 

Keywords

Delphi, VCL, Crystal Reports XI , KBA , BI , Business intelligence solutions , How To

Product

SAP Crystal Reports XI