I am working on project for class and we need to generate crystal reports. I am using Visual Studio 2013 and operating with Crystal Reports for SP15. I have created a report and placed a crystal viewer on a blank asp.net webform however when I run the webform it asks for a database login. Has anyone experienced this issue or can anyone help me please? Thank you!
**Here is the code for my webfrom page:
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Imports System.Data
Imports System.Data.SqlClient
Partial Class Default2
Inherits System.Web.UI.Page
Dim MyReport As SqlConnection
Dim COMMAND As ReportDocument
Dim ALMOST As SqlCommand
Dim adp As SqlDataAdapter
Dim DT As DataSet
Protected Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click
Dim commandString As String = ConfigurationManager.ConnectionStrings("HouseSwappingConnectionString").ConnectionString
Using con As New SqlConnection(commandString)
Using cmd As New SqlCommand("Select * from ListTable", con)
cmd.CommandType = CommandType.Text
Dim da As New SqlDataAdapter(cmd)
Dim ds As New DataSet
da.Fill(ds)
Dim HouseSwap As New ReportDocument
HouseSwap.Load(Server.MapPath("CrystalReport.rpt"))
HouseSwap.SetDataSource(ds.Tables(0))
CrystalReportViewer1.ReportSource = HouseSwap
CrystalReportViewer1.DataBind()
CrystalReportViewer1.RefreshReport()
End Using
End Using
End Sub
Dynamically set logon parameters for the report,so that it will not ask for logon parameters during runtime. first initialize a connection parameter like
Dim ConInfo As New CrystalDecisions.Shared.TableLogOnInfo
now define the connection parameters for coninfo
ConInfo.ConnectionInfo.ServerName = ServerIP ' change with server name
ConInfo.ConnectionInfo.DatabaseName = DBname ' change with database name
ConInfo.ConnectionInfo.UserID = "sa"
ConInfo.ConnectionInfo.Password = DBPassword ' change with your password
now for all tables in the crystal report datasource set logon info as this
For intCounter As Integer = 0 To HouseSwap .Database.Tables.Count - 1
HouseSwap .Database.Tables(intCounter).ApplyLogOnInfo(ConInfo)
Next
set this before setting the datasource for the report.hope it helps.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.