Crystal Report始终会弹出登录凭证 [英] Crystal report popping up login credential always

查看:72
本文介绍了Crystal Report始终会弹出登录凭证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在尝试从VB.net 2005连接Crystal报表.请看一下我的代码:

Hi,

I''m trying to connect crystal report from VB.net 2005. Have a look my code:

Dim rptDocument As New CrystalDecisions.CrystalReports.Engine.ReportDocument()
rptdocument.Load(strReportPath)
Dim ConInfo As New CrystalDecisions.Shared.TableLogOnInfo
rptdocument.DataSourceConnections.Item(0).SetConnection("server", "db", "uname", "pwd")
rptViewer.ReportSource = rptDocument


但是,即使我提供了正确的详细信息,它也总是要求我提供登录详细信息.

*注意:服务器,数据库,uname,pwd仅用于说明目的.
任何帮助,将不胜感激.

干杯,
Asan


However it is always demanding me login details even though I supplied correct details.

*Note: server, db, uname, pwd for illustrative purpose only.
any assistance it would be greatly appreciated.

Cheers,
Asan

推荐答案

Private Sub setConn(ByRef rpt As CrystalDecisions.CrystalReports.Engine.ReportDocument)
        Dim crtableLogoninfos As New TableLogOnInfos()
        Dim crtableLogoninfo As New TableLogOnInfo()
        Dim crConnectionInfo As New ConnectionInfo()
        Dim CrTables As Tables
        Dim CrTable As Table

       

        Dim crReportDocument As CrystalDecisions.CrystalReports.Engine.ReportDocument
        crReportDocument = rpt



        'Set the ConnectionInfo properties for logging on to
        'the Database

        'If you are using ODBC, this should be the
        'DSN name NOT the physical server name. If
        'you are NOT using ODBC, this should be the
        'physical server name

        With crConnectionInfo
            .ServerName = "servername"

            'If you are connecting to Oracle there is no
            'DatabaseName. Use an empty string.
            'For example, .DatabaseName = ""

            .DatabaseName = "dbaname"
            .UserID = "username"
            .Password = "password"
        End With

        'This code works for both user tables and stored
        'procedures. Set the CrTables to the Tables collection
        'of the report

        CrTables = rpt.Database.Tables


        'Loop through each table in the report and apply the
        'LogonInfo information

        For Each CrTable In CrTables

            crtableLogoninfo = CrTable.LogOnInfo
            crtableLogoninfo.ConnectionInfo = crConnectionInfo
            CrTable.ApplyLogOnInfo(crtableLogoninfo)

            If LCase(CrTable.Location) = "command" Then
                'CrTable.Location = CrTable.Location
                Exit For
            End If
            'If your DatabaseName is changing at runtime, specify
            'the table location.
            'For example, when you are reporting off of a
            'Northwind database on SQL server you
            'should have the following line of code:

            CrTable.Location = "databasename.dbo." & CrTable.Location.Substring(CrTable.Location.LastIndexOf(".") + 1)
        Next

    End Sub




希望这会有所帮助.

UPDATE SM:添加了前置标记.虽然Answer看起来不错,但是如果答复者对已发布的代码添加了一些解释/查询者遗失了什么,那本来是完整的. :thumbsup:



来自HS:

从那里调用报告时,您需要像这样声明1个变量

ByVal rpt作为CrystalDecisions.CrystalReports.Engine.ReportDocument

之后,请按照您正在执行的所有步骤进行操作,但在dat打电话给我之前给我的cade之前,请像这样

setConn(rpt)

它将使所有与表的报告建立连接.

试试吧.

我该死的肯定会起作用.因为所有项目都在工作.

祝你好运




hope this will help.

UPDATE SM: Added pre tags. Though Answer looks fine but would had been complete if replier adds some explanation to what code has been posted/what was the enquirer missing. :thumbsup:



From HS:

from where u r calling report there u need to declare 1 variable like this

ByVal rpt As CrystalDecisions.CrystalReports.Engine.ReportDocument

after that follow all the steps u were doing but before dat call my cade which i have given to u like this

setConn(rpt)

it will make all the connection to ur report with table.

Just try it.

I am damn sure it will work. coz for ma all the projects its working.

best luck


这篇关于Crystal Report始终会弹出登录凭证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆