我的Crystal报告在加载时要求数据库登录。 [英] My Crystal reports asks for database login while loading.
问题描述
使用VS2010和MS访问开发应用程序。我正在使用水晶报告。
当我在开发系统中运行应用程序时,所有报告都是正确生成的。
但是当我在另一个系统中安装安装项目时它会问对于数据库登录对话框。
我发现它仅在我使用2个表生成特定报告时才会询问。
报告部分:
Am using VS2010 and MS access to develop an application. Am using crystal report in that.
When i ran the application in developing system, all the reports were generated correctly.
But when i installed setup project in another system it asks for database login dialog box.
I found that it asks only when i used 2 tables to generate particular report.
Report Section:
Dim Report As CrystalDecisions.CrystalReports.Engine.ReportDocument = New CrystalDecisions.CrystalReports.Engine.ReportDocument
Dim CrystalReportViewer As CrystalDecisions.Windows.Forms.CrystalReportViewer = New CrystalDecisions.Windows.Forms.CrystalReportViewer
Dim Adapter As New OleDb.OleDbDataAdapter
Dim DataSet As New DataSet
For I As Integer = 0 To UBound(TableName)
Adapter = GetDataAdeptor(QueryString(I))
Adapter.Fill(DataSet, TableName(I))
Next
'Report In the report Folder
Report.Load(Application.StartupPath & "\" & ReportName & "")
Report.SetDataSource(DataSet)
Dim logoninfo As New TableLogOnInfo()
Dim conninfo As New ConnectionInfo()
With conninfo
.Type = ConnectionInfoType.CRQE
.ServerName = Application.StartupPath & "\db.mdb"
.DatabaseName = "db.mdb"
.UserID = "Admin"
.Password = ""
End With
Report.DataSourceConnections.Clear()
For Each RTable As Table In Report.Database.Tables
RTable.LogOnInfo.ConnectionInfo = conninfo
logoninfo = RTable.LogOnInfo
logoninfo.ReportName = ReportName
logoninfo.TableName = RTable.Name
RTable.ApplyLogOnInfo(logoninfo)
Next
'Report.VerifyDatabase()
If Not [Parameter] = "" Then Report.SetParameterValue(0, [Parameter])
CrystalReportViewer.ReportSource = Report
CrystalReportViewer.RefreshReport()
If DataSet.Tables(0).Rows.Count = 0 Then
MessageBox.Show("No Records to Display")
Else : Me.Panel1.Controls.Add(CrystalReportViewer)
End If
cnn.Close()
End Sub
来电报告:
Calling Report:
Dim TableName(0) As String
Dim QueryString(0) As String
<big>'Works Fine</big>
If Me.RdobtnRecentlyUpdatedCompanies.Checked() = True Then
TableName(0) = "companydetails" 'Pass The Table That you used in the crystal Report
QueryString(0) = "SELECT * FROM companydetails where Date_Added_to_List_ >= #" &
dtp_RUC_from.Value.Date & "# and Date_Added_to_List_ <= #" _& dtp_RUC_till.Value.Date & "#
and ticker_<>'Private' order by company_name_" ' Pass the Query
'ReportForm.MdiParent = MainForm 'Pass For Mdi True
Me.ViewReport("RUCReport.rpt", TableName, QueryString, )
End If
<big>'Asks for DB Login</big>
If Me.RdobtnSCompletionDate.Checked() = True Then
If txtStudyPhase.Text.ToString() = "" Then
TableName(0) = "dgdetails"
QueryString(0) = "SELECT * FROM dgdetails where Date_Added_to_List_ between #" & _
Me.dtp_DSC_From.Value.Date & "# and #" &
dtp_DSC_Till.Value.Date & _
"# and dgdetails.company_id in (select companydetails.company_id from companydetails where
companydetails.tkr<>'Pri')" ' Pass the Query
'ReportForm.MdiParent = MainForm 'Pass For Mdi True
Me.ViewReport("DSCDReport.rpt", TableName, QueryString, )
Else
TableName(0) = "dgdetails"
QueryString(0) = "SELECT dd.* FROM dgdetails as dd INNER JOIN companydetails AS cd ON
dd.company_id = cd.company_id" & _
" WHERE dd.Date_Added_to_List_ BETWEEN #" & Me.dtp_DSC_From.Value.Date & "# AND #" &
dtp_DSC_Till.Value.Date & _
"# AND dd.Current_Phase IN (" & Me.txtStudy.Text & ") AND cd.tkr <> 'Pri'" ' Pass the Query
'ReportForm.MdiParent = MainForm 'Pass For Mdi True
Me.ViewReport("DSCDReport.rpt", TableName, QueryString, )
End If
End If
任何人都可以帮我解决这个问题吗?抓了3天
Can Anyone help me out of this??? Scratching for 3 days
推荐答案
最后我解决了!!谢谢你们..
Finally I Solved that!! Thanks guys..
Report.DataSourceConnections.Clear()
Report.DataSourceConnections.Item(0).SetConnection("Server location", "DB name", 1)
现在我发生了refreshreport()时遇到登录失败的消息。但报告生成成功。
Now i got Login failed message when refreshreport() occurs. But Report generated successfully.
在水晶报告中打开报告并转到数据库>验证数据库中2表中的所有字段....请检查...
Open your report in crystal report and go Database > Verify Database for all the fields in in the 2 table....pls check...
尝试打开字段资源管理器--->数据库字段--->右键单击 - >当前数据源--->报告连接----->报告----->属性---->设置属性为---
数据来源:.\Databasename.accdb
和代码观众形式加载为
Dim cryRpt As New ReportDocument
Dim Report1 As new rptItemWise
Dim strServerName As String
strServerName = Application.StartupPath
rptItemWise.SetDatabaseLogon(admin,,strServerName, dastabasename.accdb,真实的)
cryRpt.Load(Application.StartupPath +\\ \\ rptItemWise.rpt)
也会更改与数据源相同的报表连接我认为该代码适合您....
try that open field explorer---> database field --->Right Click -->current Data source --->reports connection----->report ----->property ----> set Property as---
Data Source: .\Databasename.accdb
and code on viewer form load as
Dim cryRpt As New ReportDocument
Dim Report1 As New rptItemWise
Dim strServerName As String
strServerName = Application.StartupPath
rptItemWise.SetDatabaseLogon("admin", "", strServerName, "dastabasename.accdb", True)
cryRpt.Load(Application.StartupPath + "\rptItemWise.rpt")
also change the report connection same as data source i think that code work for you ....
这篇关于我的Crystal报告在加载时要求数据库登录。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!