在运行时更改Crystal数据库连接 [英] Change Crystal db connection at runtime

查看:89
本文介绍了在运行时更改Crystal数据库连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我使用visual studio 2013,Crystal版本13.0.12,SQL server 2014.



i有3个sql数据库。每个在表格和视图等方面都具有完全相同的结构。

DB1

DB2

DB3



我创建了一个通过OLEDB连接到DB1的报告。

在运行时,我希望报告指向DB2 OR DB3,具体取决于用户配置文件或访问权限,即用户只能查看DB1或DB2。每个数据库都有公司敏感数据,因此用户绝不能看到任何其他数据库数据。

每个数据库都有自己的sql用户和密码用于登录/读取目的。



i尝试了以下...



 Dim _rd As ReportDocument = New ReportDocument()
Dim reportPath As String = Server.MapPath(Request(Report))
_rd.Load(reportPath)
_rd.DataSourceConnections.Clear()

Dim myConnectionInfo As ConnectionInfo = New ConnectionInfo()
Dim myTables As Tables = _rd.Database.Tables

For Each myTable As CrystalDecisions.CrystalReports.Engine.Table in myTables
Dim myTableLogonInfo As TableLogOnInfo = myTable.LogOnInfo
myConnectionInfo.ServerName =MYSERVER
myConnectionInfo.DatabaseName =DB1
myConnectionInfo.UserID =USERDB1
myConnectionInfo.Password =PASSWORDDB1
myTableLogonInfo.ConnectionInfo = myConnectionInfo
myTable.ApplyLog OnInfo(myTableLogonInfo)
下一个
CrystalReportViewer1.ReportSource = _rd





问题是每当我运行报告时它总是提示数据库登录???

服务器:正确。

用户:不正确

密码:不正确

数据库:空白



i甚至尝试设置属性EnableDatabasePrompt= False但似乎仍在寻找...



如何解决???



提前感谢



Anoop

解决方案

我从未将登录信息设置为这样的特定表。您有什么理由不能直接将登录信息设置为Crystal ReportDocument对象吗?



以下是我通过google [ ^ ]:

http://stackoverflow.com/questions/3343213/crystal-reports-setting-and-changing-the-data-来源动态地在c-sharp [ ^ ]



http://stackoverflow.com/questions/40545/replace-a-database-connection-for-report-and-all-subreports [< a href =http://stackoverflow.com/questions/40545/replace-a-database-connection-for-report-and-all-subreportstarget =_ blanktitle =New Window> ^

Hi,

Im using visual studio 2013, Crystal version 13.0.12, SQL server 2014.

i have a 3 sql databases. each has the exact same structure in terms of tables and views etc.
DB1
DB2
DB3

I have created a report that connects via OLEDB to DB1.
At runtime, i want the report to point to either DB2 OR DB3 depending on the user profile or access i.e. the user can only view either DB1 or DB2. Each DB has company sensitive data so in no way must the user see any other DB data.
Each DB has its own sql user and password for login/read purposes.

i have tried the following...

Dim _rd As ReportDocument = New ReportDocument()
Dim reportPath As String = Server.MapPath(Request("Report"))
_rd.Load(reportPath)
_rd.DataSourceConnections.Clear()

Dim myConnectionInfo As ConnectionInfo = New ConnectionInfo()
Dim myTables As Tables = _rd.Database.Tables

For Each myTable As CrystalDecisions.CrystalReports.Engine.Table In myTables
     Dim myTableLogonInfo As TableLogOnInfo = myTable.LogOnInfo
     myConnectionInfo.ServerName = "MYSERVER"
     myConnectionInfo.DatabaseName = "DB1"
     myConnectionInfo.UserID = "USERDB1"
     myConnectionInfo.Password = "PASSWORDDB1"
     myTableLogonInfo.ConnectionInfo = myConnectionInfo
     myTable.ApplyLogOnInfo(myTableLogonInfo)
Next
     CrystalReportViewer1.ReportSource = _rd



the problem is that whenever i run the report it always prompts for database login???
server: correct.
user: incorrect
password: incorrect
Database: blank

i even tried to set the property "EnableDatabasePrompt" =False but it seems to be still looking...

how do i resolve???

thanks in advance

Anoop

解决方案

I've never set login information to a specific table like that. Any reason why you can't just set the login information directly to the Crystal ReportDocument object?

Here are some examples I found via google[^]:
http://stackoverflow.com/questions/3343213/crystal-reports-setting-and-changing-the-data-source-dynamically-in-c-sharp[^]

http://stackoverflow.com/questions/40545/replace-a-database-connection-for-report-and-all-subreports[^]


这篇关于在运行时更改Crystal数据库连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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