Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CR: Logon failed (Export to pdf)

Status
Not open for further replies.

lutzs

Programmer
Oct 8, 2002
75
LU
Hi,

i have an ado.net dataset. With crystal reports i can view this dataset.
Now, i will export the report to pdf.

The programm is running but get this error message:

An unhandled exception of type 'CrystalDecisions.CrystalReports.Engine.LogOnException' occurred in crystaldecisions.crystalreports.engine.dll

Additional information: Logon failed.

What can I do?
The logon with the ado.net is successfully. And then i will export the created report.

Thanks,
Stephanie
 
i have the exact same problem..... looking for a solution. If you manged to solve it, can u please post :)

Thanks
Sid
 
hi
What version of crystal are u using?
pgtek
 
I am using Crystal Report for VS.NET 2003. I am creating a Webform.

I made a detailhours.rpt in the project and it gets the information from a dataset. I can connect to the database fine and fill up the dataset with the required information and the report appears as expected when it runs.

I have a button on my webform that has this code (that I borrowed from the net) to export the report to a .pdf file:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim myReport As detailhours = New detailhours
Dim DiskOpts As CrystalDecisions.Shared.DiskFileDestinationOptions = New CrystalDecisions.Shared.DiskFileDestinationOptions
myReport.ExportOptions.ExportDestinationType = CrystalDecisions.[Shared].ExportDestinationType.DiskFile
myReport.ExportOptions.ExportFormatType = CrystalDecisions.[Shared].ExportFormatType.PortableDocFormat
DiskOpts.DiskFileName = "C:\temp\outreports.rpt"
myReport.ExportOptions.DestinationOptions = DiskOpts
myReport.Export()


I get the exception

Exception Details: CrystalDecisions.CrystalReports.Engine.LogOnException: Logon failed.

Line 128: myReport.Export()

so its on the export that causes the exception.
Any help is greatly appreciated

Thanks

 
Hi

do you have this part of code somewhere

Private Sub LogOn()
'for
Dim crLogonInfo As CrystalDecisions.Shared.TableLogOnInfo
crLogonInfo = oRpt.Database.Tables(0).LogOnInfo
crLogonInfo.ConnectionInfo.ServerName = "yuav"
crLogonInfo.ConnectionInfo.UserID = "magic8"
crLogonInfo.ConnectionInfo.Password = "magic8"
crLogonInfo.ConnectionInfo.DatabaseName = "discotes"
oRpt.Database.Tables(0).ApplyLogOnInfo(crLogonInfo)
End Sub
cheers

pgtek
 
hi

I have this you can try

-------------------------------
This code exports to PDF...u can export it to any other format. Just go thru the code properly and u will understand what to do...

using CrystalDecisions.CrystalReports.Engine ;
using CrystalDecisions.Shared ;

try
{
string Fname;
bool lboolExists = false ;

ExportOptions crExportOptions = new ExportOptions();

// populating dataset and binding to report
dsCampSumm = PopulateDataSet();

// binding report again
//CampSumm is the reportname
oRptCampSumm = new CampSumm();
oRptCampSumm.SetDataSource(dsCampSumm);

//This section of code is needed to check for existence of the folder
//where the pdf file will be temporarily stored
//--------------------------------------------------------------------------
Scripting.FileSystemObject lObjFSO ;
lObjFSO = new Scripting.FileSystemObjectClass();

lboolExists = lObjFSO.FolderExists(Server.MapPath("../../SaleSourceTemplates/" + GetSessionAgencyId()));
// Check for the folder name equal to Agency_id if false create one
if (lboolExists == false)
{
lObjFSO.CreateFolder(Server.MapPath("../../SaleSourceTemplates/" + GetSessionAgencyId()));
}
//--------------------------------------------------------------------------

Fname = Server.MapPath("../../SaleSourceTemplates/" + GetSessionAgencyId() + "/") + Session.SessionID.ToString() + ".pdf";
DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();
CrDiskFileDestinationOptions.DiskFileName = Fname;
crExportOptions = oRptCampSumm.ExportOptions;
crExportOptions.DestinationOptions = CrDiskFileDestinationOptions;
crExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
crExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
oRptCampSumm.Export();

// The following code writes the pdf file to the Client’s browser.
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/pdf";
Response.WriteFile(Fname);
Response.Flush();
Response.Close();
//delete the exported file from disk
System.IO.File.Delete(Fname);
}
catch(Exception ex)
{
throw new Exception(ex.Message);
}



private DsReport PopulateDataSet()
{
dsCampSumm = new DsReport();

try
{
gstrQuery="sp_CampSumm ";

if (Request.QueryString["CampId"]=="All") //CampId
gstrQuery=gstrQuery + BusinessRules.Reports.CAMPID + ",";
else
gstrQuery=gstrQuery + Request.QueryString["CampId"] + ",";

if (Request.QueryString["CampManagerId"]=="All") //CampManagerId
gstrQuery=gstrQuery + BusinessRules.Reports.MANAGERID + ",";
else
gstrQuery=gstrQuery + Request.QueryString["CampManagerId"] + ",";

if (Request.QueryString["StartDate"]!=null) //Start Date
gstrQuery=gstrQuery + "'" + Request.QueryString["StartDate"] + "'" + ",";
else
gstrQuery=gstrQuery + "''" + ",";

if (Request.QueryString["Status"]!=null) //Status
gstrQuery=gstrQuery + "'" + Request.QueryString["Status"] + "'" + ",";
else
gstrQuery=gstrQuery + "'" + BusinessRules.Reports.STATUSBOTH + "'" + ",";

if (Request.QueryString["Launch"]!=null) //Launched
gstrQuery=gstrQuery + "'" + Request.QueryString["Launch"] + "'" + ",";
else
gstrQuery=gstrQuery + "'" + BusinessRules.Reports.LAUNCHBOTH + "'" + ",";

gstrQuery=gstrQuery + GetSessionAgencyId() + ",";
gstrQuery=gstrQuery + GetSessionBranchId();

SqlConnection myconnection = new SqlConnection() ;
//myconnection.ConnectionString = "server=DEBARSHI;database=SaleSource;uid=SSAdmin;pwd=admin";
myconnection.ConnectionString = "Server=" + GetDatabaseServerName() + ";" +
"Database=" + GetDatabaseName() + ";" +
"uid=" + GetSQLUserId() + ";" +
"pwd=" + GetSQLPassword();
myconnection.Open();

SqlCommand mycommand = new SqlCommand();
mycommand.Connection = myconnection;
mycommand.CommandText = gstrQuery;
mycommand.CommandType = CommandType.Text;

SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = mycommand;
da.Fill(dsCampSumm, "CampaignSummary");
}
catch(Exception pEx)
{
throw new SaleSourceException(pEx.Message + " " + pEx.StackTrace,pEx,GetSessionUserId());
}
return dsCampSumm;
-----------------------------

cheers

pgtek
 
thanks for your help... your suggestions were well noted, i tried your first suggestion (didnt work).. I dont think i need to re-login to te database server since i have the data already available in the dataset.

Your longer answer was something i already tried before (the export to pdf part that is). Any other tips?

I hear it something to do with creating?(or making sure it exists) a virtual directory called CrystalReportFormViewer in your default web page (in IIS) and having it point to
"C:\Program Files\Microsoft Visual Studio .NET 2003\Crystal Reports\Viewers"

but im not really that sure. I have that, but i still have the same problem... :(

assistance?
 
I had the exact problem as SidTheSquid has. The problem is that I forgot to reconnect the report object to the datasource when the export button (button1) is clicked.
you have to remember that eventhough the report object got the connection the first time when it loaded up the view, it lost the connection when you click the export button.

for SidTheSquid's code, just add a few lines after declaration of the myReport to reconnect the report object to datasource.
see sample below

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim myReport As detailhours = New detailhours

Dim objDS1 As New Dataset1()

Dim oleConn As New OleDbConnection("Provider=SQLOLEDB.1;Password=password;User ID=loginid;Initial Catalog=databasename;Data Source=servername")

Dim oleAdapter As New OleDbDataAdapter("select * from tblmember", oleConn)

oleAdapter.Fill(objDS1, "tblMember")

myReport.SetDataSource(objDS1)


Dim DiskOpts As CrystalDecisions.Shared.DiskFileDestinationOptions = New CrystalDecisions.Shared.DiskFileDestinationOptions
myReport.ExportOptions.ExportDestinationType = CrystalDecisions.[Shared].ExportDestinationType.DiskFile
myReport.ExportOptions.ExportFormatType = CrystalDecisions.[Shared].ExportFormatType.PortableDocFormat
DiskOpts.DiskFileName = "C:\temp\outreports.rpt"
myReport.ExportOptions.DestinationOptions = DiskOpts
myReport.Export()



hope it helps.
Toddt
 
I have a question about this thread.

If you need to re-establish a connection to the data source after clicking on the "export" button (in the code samples above), does that mean that the report is being run again? I want to be clear that my data from the original query is being exported, not data from a new query after re-establishing the connection.

Gracias.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top