|
-
Dec 16th, 2008, 03:00 AM
#1
Thread Starter
Addicted Member
[RESOLVED] database login
i have created an application and crystal report using Visual Studio 2005
, the application able to show and print the report in my pc, and working fine.
I also created the setup.exe to deploy the crystal report into other
computer, but when i click the button to generate report,
the Crystal Report Viewer show a Database Login screen everytime.
Please help me out. Thanks.
here is my code.
Code:
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Web
Imports System.IO
Imports CrystalDecisions.Shared
Public Class frmGLTransaction_listing
Private con As New Clsappconfiguration
Private rptsummary As New ReportDocument
Private Sub btnPreview_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPreview.Click
'rptsummary.Refresh()
rptsummary.Load(Application.StartupPath & "\Accounting Reports\gl_transaactionlisting.rpt")
Logon(rptsummary, con.Server, con.Database, con.Username, "sa")
rptsummary.Refresh()
rptsummary.SetParameterValue("@frmMth", cboMth1.SelectedItem)
rptsummary.SetParameterValue("@toMth", cboMth2.SelectedItem)
rptsummary.SetParameterValue("@year", cboYear.SelectedItem)
rptsummary.SetParameterValue("@sortedby", cboSorted.SelectedItem)
rptsummary.SetParameterValue("@frmAcnt", cboAcnt1.SelectedItem)
rptsummary.SetParameterValue("@toAcnt", cboAcnt2.SelectedItem)
rptsummary.SetParameterValue("@fxKeyCompany", gCompanyID())
Me.crvRpt.Visible = True
Me.crvRpt.ReportSource = rptsummary
End Sub
Function Logon(ByVal cr As ReportDocument, ByVal server As String, ByVal db As String, ByVal id As String, ByVal pass As String) As Boolean
Dim ci As New ConnectionInfo
Dim subObj As SubreportObject
ci.ServerName = server
ci.DatabaseName = db
ci.UserID = id
ci.Password = pass
If Not (ApplyLogon(cr, ci)) Then
Return False
End If
Dim obj As ReportObject
For Each obj In cr.ReportDefinition.ReportObjects()
If (obj.Kind = ReportObjectKind.SubreportObject) Then
subObj = CType(obj, SubreportObject)
If Not (ApplyLogon(cr.OpenSubreport(subObj.SubreportName), ci)) Then
Return False
End If
End If
Next
cr.Refresh()
Return True
End Function
Function ApplyLogon(ByVal cr As ReportDocument, ByVal ci As ConnectionInfo) As Boolean
Dim li As TableLogOnInfo
Dim tbl As Table
For Each tbl In cr.Database.Tables
li = tbl.LogOnInfo
li.ConnectionInfo = ci
tbl.ApplyLogOnInfo(li)
If (tbl.TestConnectivity()) Then
If (tbl.Location.IndexOf(".") > 0) Then
tbl.Location = tbl.Location.Substring(tbl.Location.LastIndexOf(".") + 1)
Else
tbl.Location = tbl.Location
End If
Else
Return False
End If
Next
Return True
End Function
End Class
-
Dec 16th, 2008, 03:21 AM
#2
Thread Starter
Addicted Member
Re: database login
i even tried to hardcode this part
Code:
Logon(rptsummary, con.Server, con.Database, con.Username, "sa")
and change it to
Code:
Logon(rptsummary, "myServer", "testdatabase", "admin", "sa")
but to no avail, nothing happened, it still asked for the database login everytime i generate the report.
-
Dec 16th, 2008, 08:07 AM
#3
-
Dec 16th, 2008, 08:41 AM
#4
Re: database login
Here is what I use to set up CR reports
vb.net Code:
Public Sub outputToPrinter(ByVal mRepName As String, ByVal mstrW As String, Optional ByVal strPars As String = "")
Dim ConInfo As New CrystalDecisions.Shared.TableLogOnInfo
Dim paraValue As New CrystalDecisions.Shared.ParameterDiscreteValue
Dim currValue As New CrystalDecisions.Shared.ParameterValues
'Sub report object of crystal report.
Dim mySubReportObject As CrystalDecisions.CrystalReports.Engine.SubreportObject
'Sub report document of crystal report.
Dim mySubRepDoc As New CrystalDecisions.CrystalReports.Engine.ReportDocument
Dim i, x, z As Integer 'Some Counters
Dim mRep As New CrystalDecisions.CrystalReports.Engine.ReportDocument
Try
' Load the report
'Need to add the Report dll yet nothing works
Dim rep As New RSMReports.clsReports(mRepName)
mRep = rep.returnRep()
mRep.RecordSelectionFormula = mstrW
'SQL Server
ConInfo.ConnectionInfo.UserID = "xxxx"
ConInfo.ConnectionInfo.Password = "xxxxxxxxi"
ConInfo.ConnectionInfo.ServerName = mdlGeneral.serverName
ConInfo.ConnectionInfo.DatabaseName = mdlGeneral.dbName
For i = 0 To mRep.Database.Tables.Count() - 1
mRep.Database.Tables(i).ApplyLogOnInfo(ConInfo)
Next i
'Check for Subreprots
For i = 0 To mRep.ReportDefinition.Sections.Count - 1
For x = 0 To mRep.ReportDefinition.Sections(i).ReportObjects.Count - 1
With mRep.ReportDefinition.Sections(i)
If .ReportObjects(x).Kind = CrystalDecisions.Shared.ReportObjectKind.SubreportObject Then
mySubReportObject = CType(.ReportObjects(x), CrystalDecisions.CrystalReports.Engine.SubreportObject)
mySubRepDoc = mySubReportObject.OpenSubreport(mySubReportObject.SubreportName)
For z = 0 To mySubRepDoc.Database.Tables.Count - 1
mySubRepDoc.Database.Tables(z).ApplyLogOnInfo(ConInfo)
Next z
End If
End With
Next x
Next i
'Parameter Fields
If strPars.Trim() <> String.Empty Then
Dim arPars As String() = strPars.Split("~")
Dim strVal As String()
For xx As Integer = 0 To arPars.GetUpperBound(0)
strVal = arPars(xx).Split("=")
paraValue.Value = strVal(1)
currValue = mRep.DataDefinition.ParameterFields(strVal(0)).CurrentValues
currValue.Add(paraValue)
mRep.DataDefinition.ParameterFields(xx).ApplyCurrentValues(currValue)
Next
End If
mRep.PrintToPrinter(1, False, 0, 0)
Catch crExp As CrystalDecisions.CrystalReports.Engine.LoadSaveReportException
MessageBox.Show("Error printing Report " & mRepName & System.Environment.NewLine & _
"The error number is: " & Err.Number.ToString() & System.Environment.NewLine & _
"The error Message is: " & System.Environment.NewLine & crExp.Message.Trim(), "Print Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Catch ex As Exception
MessageBox.Show("Error printing Report " & mRepName & System.Environment.NewLine & _
"The error number is: " & Err.Number.ToString() & System.Environment.NewLine & _
"The error Message is: " & System.Environment.NewLine & ex.Message.Trim(), "Print Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Finally
mRep.Dispose()
End Try
End Sub
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Dec 16th, 2008, 08:49 PM
#5
Thread Starter
Addicted Member
Re: database login
Thank you so much, i will study your code and see if it works.
others are still welcome to help. I will appreciate it. Thank you.
-
Dec 16th, 2008, 10:01 PM
#6
Thread Starter
Addicted Member
Re: database login
I have set my datasource location to (local) thinking it would avoid the problem of looking for server when testing on other pc, however, i am still prompted by that "database login" please help
-
Dec 17th, 2008, 01:23 AM
#7
Thread Starter
Addicted Member
Re: database login
Hi to all! i have finally solve my problem. for all these headaches, it all boiled down to connections. I have selected sql native client instead of SQLOLEDB. if there are developers out there who would encounter problems like these, you can also check if you chose the correct connections in the database expert for your report in the crystal report. Thank you.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|