Hello Guys,
I have tried your suggestions, but still couldn't solve the issue: DATABASE LOGON FAIL. I created a Crystal Report in ASP.NET and used
VB.NET to export this report to PDF. I got "Database Logon Fail" error when attempt to exporting... I work with Access Database & did check Database and directory's permission, but still couldn't solve my problem. Would you guys please help! I am not sure what's going on since some other developers look at my code and they said, it should work!!! But somehow it didn't!!!!!...
Many thanks in advance for your help.
--Iris
************************************************** *****
Public Class generateCRpt
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Protected WithEvents exportPDF As System.Web.UI.WebControls.Button
Protected WithEvents CrystalReportViewer1 As CrystalDecisions.Web.CrystalReportViewer
'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Dim rpt As New CrystalReport
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim intID = Server.UrlDecode(Request.QueryString("nintid"))
If Page.IsPostBack = False Then
'Response.Write("<br>")
'Response.Write("Qstring = " & intID)
'Response.Write("<br>")
Else
'Response.Write("goofy you")
End If
'Dim myConnection As OleDbConnection
Dim myCommand As New OleDbCommand
Dim myDA As New OleDbDataAdapter
Dim myDS As New Dataset1
'Try
Dim strCnn As String = "Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source=C:\Inetpub\wwwroot\InterviewPacketCrystalRe port\CUSTOMER.mdb;"
Dim myConnection As New OleDbConnection(strCnn)
myCommand.Connection = myConnection
'myCommand.CommandText = "SELECT * FROM tblInterviewCR WHERE IntCR_ID =" & intID ' put back when done
myCommand.CommandText = "SELECT * FROM tblInterviewCR WHERE IntCR_ID =" & 47
'myCommand.CommandText = "SELECT * FROM tblInterviewCR"
myCommand.CommandType = CommandType.Text
myDA.SelectCommand = myCommand
myDA.Fill(myDS, "tblInterviewCR")
rpt.SetDataSource(myDS)
CrystalReportViewer1.ReportSource = rpt
'Catch ex As Exception
'Response.Write("There is a technical problem occurred during your building process. Please contact Training Developement for further information.")
'End Try
End Sub
Sub ExportToPDF(ByVal sender As System.Object, ByVal e As System.EventArgs)
'*** start Login Fail
rpt = New CrystalReport
Dim crTableLogoninfos As New TableLogOnInfos
Dim crTableLogoninfo As New TableLogOnInfo
Dim crConnectionInfo As ConnectionInfo
crTableLogoninfos = New TableLogOnInfos
crTableLogoninfo = New TableLogOnInfo
crConnectionInfo = New ConnectionInfo
With crConnectionInfo
.ServerName = "X00E490"
.DatabaseName = "CUSTOMER"
.UserID = "Admin"
.Password = ""
End With
crTableLogoninfo.ConnectionInfo = crConnectionInfo
crTableLogoninfo.TableName = "tblInterviewCR"
crTableLogoninfos.Add(crTableLogoninfo)
CrystalReportViewer1.LogOnInfo = crTableLogoninfos
CrystalReportViewer1.ReportSource = rpt
'CrystalReportViewer1.DataBind()
'*** end Login Fail
Dim crReportDocument As ReportDocument
crReportDocument = New ReportDocument
'Load crystal report for ready to export
crReportDocument.Load("C:\Inetpub\wwwroot\Intervie wPacketCrystalReport\CrystalReport.rpt")
'CrystalReportViewer1.ReportSource = crReportDocument
'Dim crExportOptions As ExportOptions
Dim crDiskFileDestinationOptions As DiskFileDestinationOptions
Dim ExportPath As String
Dim ExportedFileName As String
ExportPath = Request.PhysicalApplicationPath + "ExportDir\"
' check for exporting directory, if it's not exist then create one
If Directory.Exists(ExportPath) = False Then
' PhysicalApplicationPath is
http://localhost/CrystalReport/
Directory.CreateDirectory(Request.PhysicalApplicat ionPath + "ExportDir\")
End If
crDiskFileDestinationOptions = New DiskFileDestinationOptions
'crExportOptions = crReportDocument.ExportOptions
' exporting to PDF
ExportedFileName = "CrystalReport.rpt.pdf"
crDiskFileDestinationOptions.DiskFileName = ExportPath + "CrystalReport.rpt.pdf"
With crReportDocument.ExportOptions
.ExportDestinationType = ExportDestinationType.DiskFile
.ExportFormatType = ExportFormatType.PortableDocFormat
.DestinationOptions = crDiskFileDestinationOptions
End With
Try
' using Export() method
crReportDocument.Export()
Response.Write("")
Response.Write("<a href=ExportDir/" + ExportedFileName + ">Click here to View Exported Report</a>")
Response.Write("")
Catch err As OutOfLicenseException
Response.Write("<br>")
Response.Write("<b style:font-color=red>Server Busy, Please Try Later. <br />OR <br />Contact System Administrator.</b>")
Catch err1 As Exception
Response.Write("<br>")
Response.Write(err1.Message.ToString)
End Try
End Sub
End Class
************************************************** ***