Login Prompt
Hello,
I have a report that when run for the first time the application is
started it is asking for a Username and password to connect to the
datasource.
Normally this is overcome as I place a TDatabase component on the same form
as the ppReport and set the login options.
I think this is not working because the report has multiple queries and the
login appears when in code
"ppReport1.AutoSearchFieldByName('SalesCode').SearchExpression" is assigned
to which is in the second query.
Is there a way of assigning the Database component to each query in a
similar way to setting the dsn by retrieving each of the daSQL objects.
regards
Steve
I have a report that when run for the first time the application is
started it is asking for a Username and password to connect to the
datasource.
Normally this is overcome as I place a TDatabase component on the same form
as the ppReport and set the login options.
I think this is not working because the report has multiple queries and the
login appears when in code
"ppReport1.AutoSearchFieldByName('SalesCode').SearchExpression" is assigned
to which is in the second query.
Is there a way of assigning the Database component to each query in a
similar way to setting the dsn by retrieving each of the daSQL objects.
regards
Steve
This discussion has been closed.
Comments
Sorry for the delay in this response.
Which DB are you connecting to? Are you using an application similar to the
end-user solution located in the \RBuilder\Demos\End User\... directory?
Are you using DADE to connect to your datasets?
--
Regards,
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
The Database is Pervasive SQL, Using ODBC.
I have a form with a VCL ppReport on/ form also contains a TDatabase
component with LoginPrompt=FALSE.
I am NOT using any Pipeline components.
------------------------------------------------------
I am using the LoadFromFile to load the .RTM.
I use ppReport1.PrinterSetup to set printername/BinName/Copies.
I then push the search criteria in:-
if ppReport1.AutoSearchFieldByName('CustomerCode') <> nil then
ppReport1.AutoSearchFieldByName('CustomerCode').SearchExpression
:= SearchCustomer;
if ppReport1.AutoSearchFieldByName('SalesCode') <> nil then
ppReport1.AutoSearchFieldByName('SalesCode').SearchExpression :=
SearchSalesCode;
ppReport1.ShowAutoSearchDialog := FALSE;
ppReport1.Print;
------------------------------------------------------
When the line of code
"ppReport1.AutoSearchFieldByName('SalesCode').SearchExpression :=
SearchSalesCode;" executes the login prompt appears, as if a second session
is being established.
The data tab contains a number of linked queries, all are just 1-1 links.
(apart from CustomerDocuments which is used for a subreport).
AutoSearch "CustomerCode" is in the query "CustomerTable"
AutoSearch "SalesCode" is in the query "Customer2SalesCodes"
I have tried changing the CustomerTable Query to include
"Customer2SalesCodes" as a join so both autosearch fields are within the
same query, when I do this it still asks to login but when print is called.
The issue you are seeing is most likely due to the fact that some of the
queries were created with the default database and were saved to the
template with that setting. Now, even though you are changing the
datasettings to use the TDataBase on your form, each individual query is
still using the default one that requires a login. Take a look at the
following article on resolving this issue.
-------------------------------------------------
Tech Tip: How to modify the DatabaseName stored
with a DADE Query
-------------------------------------------------
Currently when DADE is used to create dataviews, the DatabaseName is stored
as part of the query definition. (This is consistent with Delphi's approach
to specifying a database connection for a Query object).
In some cases, you may decide that the
DatabaseName needs to be modified at a later date.
We recommend that the DatabaseName refer to a TDatabase connection component
or to an Alias to provide flexibility for changing the connection
parameters.
A second way to handle this issue is to implement some code that specifies a
DatabaseName whenever a template is loaded. This can be accomplished by
using the Report.Template.OnLoadEnd event.
1. Declare an event-handler procedure in the private
section of your form declaration.
type
myForm = class(TForm)
private
procedure ReportTemplateLoadEndEvent(Sender: TObject);
public
end;
2. Use the FormCreate event to assign the event-handler to
the event property.
procedure myForm.FormCreate(Sender: TObject)
begin
Report1.Template.OnLoadEnd := ReportTemplateLoadEndEvent;
end;
3. Add code to the event-handler to specify the database name.
procedure myForm.ReportTemplateLoadEndEvent(Sender: TObject)
var
lSQL: TdaSQL;
begin
if GetSQLObject(Report1, lSQL) then
begin
lSQL.DatabaseName := Designer.DataSettings.DatabaseName;
SetSQLObject(Report, lSQL);
lSQL.Free;
end;
end;
4. Below is a tech tip for extracting the SQL object from a report. TdaSQL
is a class defined in daSQL.pas. The example code extracts only
DataViews[0]. If the report contains multiple dataviews, you will need to
iterate thru all of the entries in the DataViews[] array.
-------------------------------------------------
Tech Tip: How to access the SQL object associated
with a Report created using DADE
-------------------------------------------------
uses
daDatMod;
function GetSQLObject(aReport: TppReport; var aSQL: TdaSQL): Boolean;
var
lDataModule: TdaDataModule;
lDataView: TdaDataView;
begin
aSQL := TdaSQL.Create(nil);
{get the datamodule}
lDataModule := daGetDataModule(aReport);
if (lDataModule <> nil) then
begin
lDataView := lDataModule.DataViews[0];
if (lDataView <> nil) and (lDataView is TdaQueryDataView) then
aSQL.Assign(TdaQueryDataView(lDataView).SQL);
end;
Result := (aSQL <> nil);
end;
procedure SetSQLObject(aReport: TppReport; aSQL: TdaSQL);
var
lDataModule: TdaDataModule;
lDataView: TdaDataView;
begin
{get the datamodule}
lDataModule := daGetDataModule(aReport);
if (lDataModule <> nil) then
begin
lDataView := lDataModule.DataViews[0];
if (lDataView <> nil) and (lDataView is TdaQueryDataView) then
TdaQueryDataView(lDataView).SQL := aSQL;
end;
end;
--
Regards,
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
I am not sure if this is what you meant, but i have already tried (as a
test) the code below to hard code the database name into all of the queries.
aSQL := nil;
{get the datamodule}
lDataModule := daGetDataModule(ppReport1);
if (lDataModule <> nil) then
begin
for i := 0 to lDataModule.DataViewCount-1 do
begin
lDataView := lDataModule.DataViews[i];
if (lDataView <> nil) and (lDataView is TdaQueryDataView) then
begin
aSQL := TdaQueryDataView(lDataView).SQL;
aSQL.DatabaseName := 'MyDB';
end;
end;
end;
adding the above onLoadEnd made no difference.
regards
Steve
essentially modifying a copy of the QueryDataView.SQL object. You left out
the step of assigning the modified SQL object back to the QueryDataView.
lSQL := myQueryDataView.SQL; // returns a copy
lSQL.DatabaseName := myConnectionObject.Name; // modify the copy
myQueryDataView.SQL := lSQL; // assign modified SQL object to DataView
--
Nard Moseley
Digital Metaphors
www.digital-metaphors.com
"
Best regards,
Nard Moseley
Digital Metaphors
www.digital-metaphors.com
regards
Steve