Crystal Reports要求数据库登录信息?

时间:2013-04-26 19:35:46

标签: .net security ms-access login crystal-reports

我使用的Access数据库没有特定的安全设置。我可以通过资源管理器打开数据库,但是当我尝试打开一个报告时,它要求输入的登录凭据没有。我在“数据库登录”对话框中注意到,有一个字段显示“服务器名称”,它是我在报告中使用的对象的名称空间和类名。造成这种情况的原因是什么?

///DAL Class
Option Strict On
Imports System.Data.OleDb
Imports FPCReportBuilder.Utilities
Namespace FPCReportBuilder.Data
    Public Class DAL
        Inherits DALCnn
        Public Shared Function GetDataTableUsingReader(ByVal sql As String, Optional ByVal parameterList As List(Of DataParameter) = Nothing, Optional ByVal type As CmdType = CmdType.StoredProcedure) As DataTable
            Dim cmd As OleDbCommand = CreateCommand(sql, parameterList, type)
            Dim dt As New DataTable
            Using cmd.Connection
                cmd.Connection.Open()
                dt.Load(cmd.ExecuteReader(CommandBehavior.CloseConnection))
            End Using
            Return dt
        End Function

        Private Shared Function CreateCommand(ByVal sql As String, Optional ByVal parameters As List(Of DataParameter) = Nothing, Optional ByVal type As CmdType = CmdType.StoredProcedure) As OleDbCommand
            Dim cmd As New OleDbCommand(sql, GetConnection())
            If type = CmdType.StoredProcedure Then
                cmd.CommandType = CommandType.StoredProcedure
            Else
                cmd.CommandType = CommandType.Text
            End If
            If Not parameters Is Nothing Then
                For Each parameter As DataParameter In parameters
                    Dim newParameter As OleDbParameter = cmd.CreateParameter()
                    newParameter.ParameterName = parameter.Name
                    newParameter.Value = parameter.Value
                    newParameter.OleDbType = parameter.DbType
                    newParameter.Direction = parameter.Direction
                    newParameter.Size = parameter.Size
                    cmd.Parameters.Add(newParameter)
                Next
            End If
            Return cmd
        End Function
    End Class
End Namespace

///DALCnn Class
Option Strict On
Imports System.Data.OleDb
Namespace FPCReportBuilder.Data
    Public MustInherit Class DALCnn
        Protected Friend Shared Function GetConnection() As OleDbConnection
            Return New OleDbConnection(My.Settings.cnnString)
        End Function
    End Class
End Namespace

当我通过代码运行它时,一切正常。当我调用像ReportData.GetSection1Complete()这样的公共共享方法这样的类时,它会使数据恢复正常。

编辑*

我似乎正在某个地方。我已将ReportDate属性添加到MainReport.rpt文件的页脚,以显示在报表的每个页面上。当我触发btnViewReport.Click方法,包含实际的Crystal ReportViewer控件的ReportViewer表单时,我就像这样填充数据源......

Private Sub btnViewReport_Click(sender As System.Object, e As System.EventArgs) Handles btnViewReport.Click
        Try
            Dim repViewer As New ReportViewer()
            Dim reportList As New List(Of Report)
            reportList.Add(objReport)
            repViewer.MainReport1.Database.Tables("Report").SetDataSource(reportList)
Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
End Sub

这似乎有效。但是MainReport.rpt包含一个SubReport,它也包含一个SubReport。我试图从另一个名为ReportData.GetSection1Complete()的类中调用一个Method来填充SubReport中的数据,但我似乎无法弄清楚如何填充该特定的DataSource。我试过......

repViewer.MainReport1.Subreports("Section1.rpt").Subreports("Section1Complete.rpt").Database.Tables("ReportData").SetDataSource(ReportData.GetSection1Complete())

这给了我一个“子报告中不支持”。例外。

2 个答案:

答案 0 :(得分:1)

当您使用Access打开未配置用户级安全性的数据库时,您将自动(并以静默方式)以用户Admin身份登录。当Crystal Reports提示您输入凭据时,请尝试使用带有空密码的用户名Admin。如果可行,请查看Crystal Reports是否提供“保存密码”或“保存登录信息”等选项。

答案 1 :(得分:0)

我不确切地知道为什么要求我登录,但我发现如果我事先没有填充对象数据源就会这样做。当我在按钮上填充数据源时单击加载报表查看器的数据源,它不会要求登录。我遇到的另一个问题是,当我在子报表中有子报表时,它不会显示。经过一些研究,我发现你不能在子报告中有子报告,所以当我解封报告时,数据现在显示得很好。感谢大家的帮助。