简体   繁体   English

如何在没有凭据的情况下在Web查看器中加载Crystal报表?

[英]How can I load crystal reports in web viewer without credentials?

Hello we have an in house vb.net based application that will allow users to load and access reports that we have generated on a file server. 您好,我们有一个基于vb.net的内部应用程序,该应用程序将允许用户加载和访问我们在文件服务器上生成的报告。 When they are created they are made in the visual studio designer using an ODBC connection. 创建它们时,它们是在Visual Studio设计器中使用ODBC连接制作的。 We have decided to port this application over to a web based system using asp.net but have ran into a snag. 我们已经决定使用asp.net将此应用程序移植到基于Web的系统上,但遇到了麻烦。 The viewer on the web page will load the reports (we can verify this by date criteria that appears on some) but a login page will appear that ask us for the following fields; 网页上的查看器将加载报告(我们可以通过某些日期显示的日期标准来对此进行验证),但是会出现一个登录页面,要求我们提供以下字段; Server Name, Database name, User name, and password. 服务器名称,数据库名称,用户名和密码。 The top field being the server name is incorrect in that its not a valid hostname, unfortunately it will not let us change it. 服务器名称的顶部字段是错误的,因为它不是有效的主机名,但是很遗憾,它不允许我们更改它。 I have tried various in-code methods to override this message. 我尝试了各种编码方法来覆盖此消息。 I have set the credentials in the code, disabled the login in code, I even copied the exact ODBC connection settings to the server the site runs on. 我已经在代码中设置了凭据,禁用了代码登录,甚至将确切的ODBC连接设置复制到了运行该站点的服务器。 Has anyone ever had an issue with crystal reports viewer like this? 有没有人像这样的水晶报表查看器有问题?

Some of the code I use to attempt to resolve this was to create the credentials and set them for each table like so. 我用来解决此问题的一些代码是创建凭据,并为每个表设置它们,如下所示。

  For Each CrTable In CrTables
        crTableLogonInfo = CrTable.LogOnInfo
        crTableLogonInfo.ConnectionInfo =
        ConnInfo
        CrTable.ApplyLogOnInfo(crTableLogonInfo)
    Next

First you need to add the parameters into your web config as a key as follow: 首先,您需要将参数作为关键字添加到您的Web配置中,如下所示:

<add key="ServerName" value="Your Server"/>
<add key="DataBaseName" value="Your DB Name"/>
<add key="DatabaseUser" value="DB User"/>
<add key="DatabasePassword" value="DB Password"/>

Second, In your report viewer file, at bind report method add this code: 其次,在您的报表查看器文件中,在绑定报表方法中添加以下代码:

    Dim SERVER_NAME As String = ConfigurationManager.AppSettings("ServerName").ToString()
    Dim DATABASE_NAME As String = ConfigurationManager.AppSettings("DataBaseName").ToString()
    Dim DatabaseUser As String = ConfigurationManager.AppSettings("DatabaseUser").ToString()
    Dim DatabasePassword As String = ConfigurationManager.AppSettings("DatabasePassword").ToString()

Finally add this code: 最后添加以下代码:

rptobj.SetDatabaseLogon(DatabaseUser, DatabasePassword, SERVER_NAME, DATABASE_NAME)

*some developers find this approach unsecured because you are showing the DB credentials you can encrypt it and then decrypt it for security issues. *某些开发人员发现此方法不安全,因为您向您显示了数据库凭据,可以对其进行加密,然后再针对安全问题对其进行解密。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM