Click here to Skip to main content
15,886,066 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I am developed Windows Form Application using C#. Its printed bill for use the crystal report. But not bill print. comes "database logon failed" error. how can solve this problem? plzz help me.

Output:
'POS_System.exe' (CLR v4.0.30319: POS_System.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Web.Services\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Web.Services.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'POS_System.exe' (CLR v4.0.30319: POS_System.exe): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\CrystalDecisions.ReportSource\13.0.3500.0__692fbea5521e1304\CrystalDecisions.ReportSource.dll'. Cannot find or open the PDB file.
Exception thrown: 'CrystalDecisions.CrystalReports.Engine.LogOnException' in CrystalDecisions.CrystalReports.Engine.dll
The program '[15476] POS_System.exe: Program Trace' has exited with code 0 (0x0).
The program '[15476] POS_System.exe' has exited with code -1 (0xffffffff).


What I have tried:

using the ODBC connection method. So, I want to use User ID and Password for login SQL server database. Not windows authentication method.
Posted
Updated 18-Jan-18 10:16am
v2
Comments
san2debug 17-Jan-18 22:34pm    
Can you please share your code here. So that we can able to help you
Member 10071718 17-Jan-18 22:54pm    
only design part,
1 - ODBC connector create
2 - Crystal report create using ODBC connection
this is code section for print the bill,

CrystalReport1 OBjcryBill1 = new CrystalReport1();
OBjcryBill1.PrintToPrinter(1, false, 0, 0);

1 solution

Ensure you have added references to Crystal Reports as follows;
CrystalDecisions.CrystalReports.Engine
CrystalDecisions.ReportSource
CrystalDecisions.Shared
CrystalDecisions.Windows.Forms

Add the following using statements;
C#
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;

The below code is used to open a Crystal Report & apply the Logon information.
C#
// create the report object
ReportDocument rptDoc = new ReportDocument();
rptDoc.Load("<Path & file name of the report>");
// create the connection information
ConnectionInfo conRpt = new ConnectionInfor();
conRpt.ServerName = "DB Server Name";
conRpt.DatabaseName = "DB Name";
conRpt.UserID = "User name";
conRpt.Password = "Password";
// apply connection information to the report tables
Tables rptTables = rptDoc.Database.Tables;
for(int i = 0; i < rptTables.Count; i++)
{
    Table rptTable = rptTables[i];
    TableLogOnInfo tblInfo = rptTable.LogOnInfo;
    tblInfo.ConnectionInfo = conRpt;
    // next table
}
// if the report contains sub reports, you will need to set the connection info there too
if(rptDoc.SubReports.Count > 0)
{
    for(int i = 0; i < rptDoc.Subreports.Count; i++)
    {
        using(ReportDocument rptSub = rptDoc.OpenSubReport(rptDoc.SubReports[i].Name))
        {
            Tables rptTables = rptSub.Database.Tables;
            for(int i = 0; i < rptTables.Count; i++)
            {
                Table rptTable = rptTables[i];
                TableLogOnInfo tblInfo = rptTable.LogOnInfo;
                tblInfo.ConnectionInfo = conRpt;
                // next table
            }
            rptSub.Close();
        }
    }
}
// Show Report in Viewer - you can also send direct to a printer if required
// Note; do not call refresh report on the ReportViewer control as this will undo all of the above
frmReportViewer.ReportSource = rptDoc;


Kind Regards
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900