Click here to Skip to main content
14,697,444 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Am using VS2010 and MS access to develop an application. Am using crystal report in that.
When i ran the application in developing system, all the reports were generated correctly.
But when i installed setup project in another system it asks for database login dialog box.
I found that it asks only when i used 2 tables to generate particular report.

Report Section:
    Dim Report As CrystalDecisions.CrystalReports.Engine.ReportDocument = New CrystalDecisions.CrystalReports.Engine.ReportDocument
    Dim CrystalReportViewer As CrystalDecisions.Windows.Forms.CrystalReportViewer = New CrystalDecisions.Windows.Forms.CrystalReportViewer

    Dim Adapter As New OleDb.OleDbDataAdapter
    Dim DataSet As New DataSet
    For I As Integer = 0 To UBound(TableName)

        Adapter = GetDataAdeptor(QueryString(I))
        Adapter.Fill(DataSet, TableName(I))

    Next
    'Report In the report Folder
    Report.Load(Application.StartupPath & "\" & ReportName & "")
    Report.SetDataSource(DataSet)

    Dim logoninfo As New TableLogOnInfo()
    Dim conninfo As New ConnectionInfo()
    With conninfo
        .Type = ConnectionInfoType.CRQE
        .ServerName = Application.StartupPath & "\db.mdb"
        .DatabaseName = "db.mdb"
        .UserID = "Admin"
        .Password = ""
    End With
    Report.DataSourceConnections.Clear()
    For Each RTable As Table In Report.Database.Tables
        RTable.LogOnInfo.ConnectionInfo = conninfo
        logoninfo = RTable.LogOnInfo
        logoninfo.ReportName = ReportName
        logoninfo.TableName = RTable.Name
        RTable.ApplyLogOnInfo(logoninfo)
    Next

    'Report.VerifyDatabase()
    If Not [Parameter] = "" Then Report.SetParameterValue(0, [Parameter])


    CrystalReportViewer.ReportSource = Report
    CrystalReportViewer.RefreshReport()

    If DataSet.Tables(0).Rows.Count = 0 Then
        MessageBox.Show("No Records to Display")
    Else : Me.Panel1.Controls.Add(CrystalReportViewer)

    End If

    cnn.Close()
End Sub


Calling Report:
Dim TableName(0) As String
Dim QueryString(0) As String

<big>'Works Fine</big>
    If Me.RdobtnRecentlyUpdatedCompanies.Checked() = True Then
    TableName(0) = "companydetails" 'Pass The Table That you used in the crystal Report
    QueryString(0) = "SELECT * FROM companydetails where Date_Added_to_List_ >= #" &        
  dtp_RUC_from.Value.Date & "# and Date_Added_to_List_ <= #" _& dtp_RUC_till.Value.Date & "#
     and ticker_<>'Private' order by company_name_" ' Pass the Query
    'ReportForm.MdiParent = MainForm 'Pass For Mdi True
     Me.ViewReport("RUCReport.rpt", TableName, QueryString, )
     End If

<big>'Asks for DB Login</big>
    If Me.RdobtnSCompletionDate.Checked() = True Then

    If txtStudyPhase.Text.ToString() = "" Then
    TableName(0) = "dgdetails"
    QueryString(0) = "SELECT * FROM dgdetails where Date_Added_to_List_ between #" & _
                                 Me.dtp_DSC_From.Value.Date & "# and #" &    
    dtp_DSC_Till.Value.Date & _
    "# and dgdetails.company_id in (select companydetails.company_id from companydetails where 
    companydetails.tkr<>'Pri')"  ' Pass the Query
    'ReportForm.MdiParent = MainForm 'Pass For Mdi True
     Me.ViewReport("DSCDReport.rpt", TableName, QueryString, )
     Else
     TableName(0) = "dgdetails"
      QueryString(0) = "SELECT dd.* FROM dgdetails as dd INNER JOIN companydetails AS cd ON   
      dd.company_id = cd.company_id" & _
      " WHERE dd.Date_Added_to_List_ BETWEEN #" & Me.dtp_DSC_From.Value.Date & "# AND #" &   
      dtp_DSC_Till.Value.Date & _
     "# AND dd.Current_Phase IN (" & Me.txtStudy.Text & ") AND cd.tkr <> 'Pri'" ' Pass the Query
'ReportForm.MdiParent = MainForm 'Pass For Mdi True
     Me.ViewReport("DSCDReport.rpt", TableName, QueryString, )
     End If
   End If


Can Anyone help me out of this??? Scratching for 3 days
Posted
Updated 12-Oct-17 20:09pm
v5

Finally I Solved that!! Thanks guys..
Report.DataSourceConnections.Clear()
Report.DataSourceConnections.Item(0).SetConnection("Server location", "DB name", 1)


Now i got Login failed message when refreshreport() occurs. But Report generated successfully.
   
Comments
Member 11770023 20-Jun-15 7:14am
   
where to write this above code.....??
deven sharma 29-Nov-18 13:33pm
   
great its working like a cham..
Open your report in crystal report and go Database > Verify Database for all the fields in in the 2 table....pls check...
   
Comments
Vml_Newbie 26-Mar-14 0:52am
   
I tried already. Database is verified and no changes.
try that open field explorer---> database field --->Right Click -->current Data source --->reports connection----->report ----->property ----> set Property as---

Data Source: .\Databasename.accdb

and code on viewer form load as

Dim cryRpt As New ReportDocument

Dim Report1 As New rptItemWise

Dim strServerName As String
strServerName = Application.StartupPath
rptItemWise.SetDatabaseLogon("admin", "", strServerName, "dastabasename.accdb", True)



cryRpt.Load(Application.StartupPath + "\rptItemWise.rpt")

also change the report connection same as data source i think that code work for you ....
   
my solution was by installing SQL Server 2012 Client Tool Connectivity, and backward client connectivity components using SQL Server setup source.
   
Hi, i had the same problem, but I noticed that on the pc with the sqlserver already installed, the reports crystal report displayed correctly. I did research and finally I found that it was necessary to install "Microsoft® SQL Server® 2012 Native Client". and all Crystal reports are displayed without problem.

Download Microsoft® SQL Server® 2012 Native Client - QFE from Official Microsoft Download Center[^]
   
v3
Comments
Dave Kreskowiak 28-Nov-19 20:58pm
   
That's not going to work for an Access database.
CHill60 29-Nov-19 9:25am
   
You made me laugh out loud with that response. I needed a laugh today - thank you!

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