Click here to Skip to main content
15,887,585 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am able to design a report in Visual Studio 2008 with Access 2007 Database by using the ODBC or OLEDB driver. But when I try to print it (after running the code), I get the invalid logon parameters Error while it worked well with Access 2003 database. Below is my code:

creport_laundry crReportDocument = new creport_laundry();
            Database crDatabase;
            Tables crTables;
            Table crTable;
            TableLogOnInfo crTableLogOnInfo;
            ConnectionInfo crConnectionInfo = new ConnectionInfo();
 
            crConnectionInfo.ServerName = @"d:\db2.accdb";
            crConnectionInfo.DatabaseName = @"d:\db2.accdb";
 
            crConnectionInfo.Password = "xyz"
            crDatabase = crReportDocument.Database;
            crTables = crDatabase.Tables;
            for (int i = 0; i < crTables.Count; i++)
            {
                crTable = crTables[i];
                crTableLogOnInfo = crTable.LogOnInfo;
                crTableLogOnInfo.ConnectionInfo = crConnectionInfo;
                crTable.ApplyLogOnInfo(crTableLogOnInfo);
            }
crReportDocument.PrintToPrinter(1, false, 0, 0);


I have spent more than 10 hours on this without a solution. Any help would be HIGHLY appreciated.
Posted
Updated 11-Aug-16 22:19pm
v2

I have checked your code & found some issues.

You must pass values for those 4 parameters like as below
crConnectionInfo.ServerName = "MachineName";//It should be machine name
crConnectionInfo.DatabaseName = @"d:\db2.accdb";
crConnectionInfo.UserID = "Administrator";//You forgot to give value for this
crConnectionInfo.Password = "xyz"


Further Reading
C# Crystal Reports Dynamic Logon parameters[^]
 
Share this answer
 
v2
Comments
sachin100k 18-Jun-11 14:29pm    
First, it worked well with Access 2003 database
Second, For an Access Database Server name gets the complete path (and it worked for access 2003 database)
User Id and Password also follow the same rule.
Third, I followed your advice but with same results !! Please Help:(
sachin100k 18-Jun-11 14:33pm    
First, Server Name when connecting to Access Database contains the complete path and it worked well with Access 2003
Second, Even User Id and Password werent required in Access 2003 Database
Lastly, I still followed your solution but with no results. Please Help :(
First, Server Name when connecting to Access Database contains the complete path and it worked well with Access 2003
Second, Even User Id and Password werent required in Access 2003 Database
Lastly, I still followed your solution but with no results. Please Help :(
 
Share this answer
 
i hope this help :-

C#
DataSet ds = new DataSet();
            
            creport_laundry crReportDocument  = new creport_laundry();
            ReportDocument rptFile = new ReportDocument();
            ds = clsHlpr.ExecuteDataset(connection_name, CommandType.Text, "select * from abc");
            if (ds.Tables[0].Rows.Count > 0)
            {
                rptform.Text = ".........";
                rptFile.Load(Application.StartupPath + "\\mainR.rpt");
                
                crReportDocument.crys.ReportSource = rptFile;
                rptFile.SetDatabaseLogon("admin", "lbbs");
                rptFile.SetDataSource(ds);
                crReportDocument.crys.RefreshReport();
                rptFile.Refresh();
                rptFile.PrintToPrinter(1, false, 0, 0);// for send repot direct to print
                      //or
                crReportDocument.crys.Show();//for show report
                crReportDocument.Show();

                            }
 
Share this answer
 
Whats clsHlpr and crys ?
Whats mainR.rpt --- I am using Crystal Reports embedded in Visual Studio; so not sure if that file would be found;
And doing it through connection string would be my last preference as there are 100+ reports :(


.................................................................................................................

Following the above code I got to a solution but again this will mean changing 100+ reports(Any solution where connection string is not given through code(and the one used in Crystal Report Designer) is still highly welcomed :) :

CrystalReport1 rpt1=new CrystalReport1();
OleDbCommand com=new OleDbCommand("SELECT * FROM lo_bill_det");
com.CommandType = CommandType.Text;
com.Connection = con;// '' give connection to command
OleDbDataAdapter adp= new OleDbDataAdapter();// '' declare adapter
adp.SelectCommand = com ;//'' select command for adpapter to work on

adp.Fill(ds1, "Crystal");// '' fill the dataset through adapter
try
{
rpt1.DataSourceConnections[0].SetConnection("",@GlobalClass.hostIP,false); // GlobalClass.hostIP is the //database path
rpt1.DataSourceConnections[0].SetLogon("Admin", "");

}
catch
{}

rpt1.SetDataSource(ds1.Tables["Crystal"]);// '' select the Dataset to the source of the report
rpt1.PrintToPrinter(1, false, 0, 0);


A SOLUTION BUT THE EXACT SOLUTION IS STILL BEING WAITED...
 
Share this answer
 
v2
It is approved right!
I spend half day to do the research! can't find any documents on line.
VB
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim rpt As New ReportDocument
        Dim A As CrystalDecisions.CrystalReports.Engine.Table
        'Dim B As CrystalDecisions.Shared.TableLogOnInfo

        Dim tblLog As TableLogOnInfo
        rpt.Load("C:\report file.rpt")
        rpt.RecordSelectionFormula = "" '"({CommissionTable.SalesRep}='" & 123 & "') "
        Dim cnnInfo As New ConnectionInfo
        With cnnInfo
            .Type = ConnectionInfoType.CRQE  ' ODBC type
            .ServerName = "ERP" 'ODBC name, no need password here
        End With
        'rpt.Load("c:\database.mdb")
        For Each A In rpt.Database.Tables
            tblLog = A.LogOnInfo
            tblLog.ConnectionInfo = cnnInfo
            A.ApplyLogOnInfo(tblLog)
        Next

        CrystalReportViewer1.ReportSource = rpt

    End Sub
 
Share this answer
 
Comments
Richard MacCutchan 12-Aug-16 4:46am    
Pleased do not post in old questions. This one was answered more than FIVE years ago.

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