最近使用水晶报表,设计时候数据库名称为(smsd),设计rpt文件的数据源是利用存储过程生成的。
当在不同服务器上使用不同数据库名称,就会提示在sysdatabase找不到smsd......表的名称;
但是在不同服务器中使用相同数据库名称就会正常运行;以为是连接表的连接还是指向设计时候的连接,但是为什么服务器名称,用户名称,密码都是对的,惟独数据库没有更新。
如果从新验证数据库利用 database.verify 这个方法老是会弹出对话框。提示后可以正常运行。但我不要对话框不要弹出。有什么方式?有没有其它方式验证数据库,更新新的连接。
以下是调用过程:
Public Function Report(ReportName As String, ArraryGet As Variant) As CRAXDDRT.Report
On Error GoTo Err_Handle
Dim AppRpt As CRAXDDRT.Application
Dim rpt As CRAXDDRT.Report
Dim Mint As Integer
Dim tablecoleection, table, connproperty, subreport, rptsection, rptobject As Variant
Set Report = Nothing
Set Report = New CRAXDDRT.Report
Set AppRpt = Nothing
Set AppRpt = New CRAXDDRT.Application
Set rpt = Nothing
Set rpt = New CRAXDDRT.ReportSet rpt = AppRpt.OpenReport(App.Path & "\" & "Report" & "\" & ReportName, 1)
rpt.FieldMappingType = crEventFieldMapping
rpt.EnableParameterPrompting = FalseSet tablecoleection = rpt.Database.Tables ‘更新报表文件所有表的连接信息
Set table = Nothing
For Each table In tablecoleection
Set connproperty = table.ConnectionProperties("data source")
    connproperty.Value = g_strServerName    '服务器名称
Set connproperty = table.ConnectionProperties("user id")
    connproperty.Value = g_strUserName      用户名称
Set connproperty = table.ConnectionProperties("password")
    connproperty.Value = g_strPassword      '用户密码
Set connproperty = table.ConnectionProperties("initial catalog")
    connproperty.Value = g_strDataBaseName  '数据库名称
Next’向存储过程传递参数值
For Mint = 0 To Int(UBound(ArraryGet) / 2)
     rpt.ParameterFields.GetItemByName(Trim(ArraryGet((Mint * 2)))).AddCurrentValue       (ArraryGet((Mint * 2) + 1))
NextSet Report = rpt
Set rpt = Nothing
Exit Function
Err_Handle:
ShowMsg err.Description
End Function