Hi All,
I have got my crystal reports working on my development pc but when I try and deploy it, when i load a report it asks for login information, I am using VS 2010 and have an MS Access backend .mdb. I have tackled this problem before and used a typed dataset and oledbdataadapter and a fixed report, but I am loading the data from a sql statement pulled in from a xml file, then, this produces the dataset and the datatable which is then used as the datasource for the report. I chose this way as I want to be able to send reports to clients and they can load in to a file and away they go.
CrystalReport viewer
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Public Class CrystalReportViewerForm
Friend sSql As String
Friend rptName As Object
Friend ParamString As String
Friend ParamName As String
Private Sub CrystalReportViewerForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Icon = My.Resources.cheff
CrystalReportViewer2.ShowLogo = False
CrystalReportViewer2.ShowGroupTreeButton = False
Try
Dim rpt As New ReportDocument
rpt.Load(Application.StartupPath + "\Reports\" + rptName.ToString + ".rpt")
rpt.SetDataSource(ReportLoader.ReportData(sSql))
CrystalReportViewer2.ReportSource = rpt
CrystalReportViewer2.RefreshReport()
Catch ex As Exception
MessageBox.Show(ex.Message.ToString)
End Try
End Sub
This loads the data in to the dataset
Public Shared Function ReportData(ByVal sql As String) As DataSet
Dim cmd As OleDbCommand = New OleDbCommand()
Try
With cmd
.Connection = Database.conn
.CommandText = sql
End With
Dim ds As New RPTDataSet
Dim adapter As OleDbDataAdapter = New OleDbDataAdapter(cmd)
adapter.Fill(ds, "DataTable1")
ds.WriteXml(Application.StartupPath + "\Log_Files\Report.xml", XmlWriteMode.WriteSchema)
Return ds
Catch ex As Exception
Return Nothing
ErrorMsg.WriteMsg(ex, cmd.CommandText.ToString)
End Try
End Function
This is the database class which holds the connection string and works on the deployed machine just not with the report.
Imports System.Data.OleDb
Public Class Database
Public Shared conn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Persist Security Info= False; Data Source=" _
& Application.StartupPath & "\DataCatering.mdb;Jet OLEDB:Database Password=******")
End Class
Hope someone can help with this.
Regards
Aidan