在运行时更改数据源[UNRESOLVED] [英] Changing Datasource at runtime [UNRESOLVED]
问题描述
以下内容适用于Crystal Reports for Visual Studio 2005 v10.2.3600.0
THe following applies to Crystal Reports for Visual Studio 2005 v10.2.3600.0
当我将运行时报表的数据源更改为我的开发计算机以外的任何内容时,我收到以下错误...
When I change the datasource of a report at runtime to anything other than my development machine, I am getting the following errors...
"字段名称未知。"
"文件错误..."
"公式中的错误< Monday> ;"
' {?@ StartDate}'
字段名称未知
"The field name is not known."
"Error in File..."
"Error in formula <Monday>"
'{?@StartDate}'
This field name is not known
注意:**此参数是从用于创建报告的存储过程
Note: **This paramter is created from the stored procedure used to create the report
无法打开行集,过程需要未提供的参数@LocationID。
Failed to open a rowset, procedure expects parameter @LocationID which was not supplied.
注意:**在运行期间提供参数
Note: **the parameter is supplied during runtime
我已经多次复制以下内容。
I have reproduced the following several times.
1。创建了一个报告,该报告从sql server上具有
参数的存储过程中获取数据
2。使用crystalreportviewer控件创建一个vb.net项目
3。在运行时将报表绑定到控件上
4。在运行时,查看器控件将要求用户输入
5的参数值。报告按预期加载
在步骤3中,如果数据库位置更改为与开发Crystal报表时使用的服务器不同的服务器,则将发生以下操作。
- > 4。在运行时,查看器控件将要求用户为参数输入值
- > 5。报告加载失败,ADO错误说明存储的
过程未提供的预期参数。
1. Created a report that gets data from a stored procedure having
parameters on sql server
2. create a vb.net project with a crystalreportviewer control
3. bind the report to the control at runtime
4. at runtime, the viewer control will ask the user to input values for
the params
5. report loads as expected
During step 3, if the database location is changed to a different
server than the one used when developing the Crystal Report, the
following will occur.
-->4. at runtime, the viewer control will ask the user to input values
for the params
-->5. report loading fails with an ADO error stating the stored
procedure expected parameters that were not supplied.
这也是向后工作,这意味着我然后使用生产服务器创建报告,然后在运行时将数据源更改为我的开发机器,它获得与上面相同的结果。
This works backwards as well, meaning I then create a report using the production server, then change the datasource at runtime to my dev machine which gets the same results as above.
推荐答案
我在之后添加了以下代码阅读一些帖子...
I added the following code after reading some posts...
尝试
rpt.VerifyDatabase()
rpt.VerifyDatabase()
Catch ex < font color ="#0000ff"size = 2> As Exception
Catch ex As Exception
MessageBox.Show(ex.ToString)
MessageBox.Show(ex.ToString)
结束 试用
这会捕获登录错误...我已尝试以下代码来设置数据源
rpt.DataSourceConnections.Item(0).SetConnection(conn.DataSource ,conn.Database, False )
rpt.DataSourceConnections.Item(0).SetConnection(conn.DataSource, conn.Database, False)
rpt.DataSourceConnections.Item(0).SetLogon( user,pass)
rpt.DataSourceConnections.Item(0).SetLogon(user, pass)
AND
Dim conns 作为 DataSourceConnections = rpt.DataSourceConnections
Dim conns As DataSourceConnections = rpt.DataSourceConnections
Dim < font size = 2> info As IConnectionInfo = conns(0)
Dim info As IConnectionInfo = conns(0)
info.SetConnection(conn.DataSource,conn.Database, user, pass )
info.SetConnection(conn.DataSource, conn.Database, user, pass)
AND
'设置数据库登录信息
< font color ="#0000ff"size = 2>使用 crConnectionInfo
With crConnectionInfo
.ServerName = conn.DataSource
.ServerName = conn.DataSource
.DatabaseName = conn.Database
.DatabaseName = conn.Database
.UserID = user
.UserID = user
.Password = pass
.Password = pass
结束 使用
End With
'遍历报表中的每个表并应用LogonInfo信息
'Loop through each table in the report and apply the LogonInfo information
Dim CrTables As Tables = rpt.Database.Tables
Dim CrTables As Tables = rpt.Database.Tables
对于 每个 CrTable As 表 In CrTables
For Each CrTable As Table In CrTables
crtableLogoninfo = CrTable.LogOnInfo
crtableLogoninfo = CrTable.LogOnInfo
crtableLogoninfo.ConnectionInfo = crConnectionInfo
crtableLogoninfo.ConnectionInfo = crConnectionInfo
CrTable.ApplyLogOnInfo(crtableLogoninfo)
CrTable.ApplyLogOnInfo(crtableLogoninfo)
Next
Next
这篇关于在运行时更改数据源[UNRESOLVED]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!