I'm using crystal reports 2011 and Visual studio 2008
I have a ctystal report viewer on an aspx page with autobind set to true and have the following code to connect to the database passing a user name and password which works just fine:
Code:
If Not IsPostBack Then
Dim conninfo As New CrystalDecisions.Shared.ConnectionInfo
With conninfo
.ServerName = "ServerName"
.DatabaseName = "dbname"
.UserID = "username"
.Password = "password"
End With
For Each cnInfo As CrystalDecisions.Shared.TableLogOnInfo In Me.CrystalReportViewer1.LogOnInfo
cnInfo.ConnectionInfo = conninfo
Next
End If
The reports takes a while to open so my boss has instructed me not to open the report when the page opens but instead to put a button on the report that the user can click to open the report.
I set AutoDataBind to false but now the code no longer works. It’s a very simple report with no paramaters – the only thing I have to do is pass the user name and password. Here is the final code I’m trying to use. I’ve tried placing the Autobind statemnt before and after the connection info and neither one works.
Code:
Protected Sub cmdViewReport_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdViewReport.Click
'Me.CrystalReportViewer1.DataBind()
Dim conninfo As New CrystalDecisions.Shared.ConnectionInfo
With conninfo
.ServerName = "ServerName"
.DatabaseName = "DatabaseName"
.UserID = "username"
.Password = "password"
End With
For Each cnInfo As CrystalDecisions.Shared.TableLogOnInfo In Me.CrystalReportViewer1.LogOnInfo
cnInfo.ConnectionInfo = conninfo
Next
Me.CrystalReportViewer1.DataBind()
End Sub
Can someone help me figure this out.
Thanks in advance