我们需要将一些 Crystal Reports 8.5 连接到 MS Windows 7 64 位下的 SQL Server 数据库。查询不是由我们应用程序的 VB6 代码处理,而是包含在报告中,到那时,我们希望避免传递从代码中提取的数据,因为我们应该深入修改所有报告。由于应用程序将安装在不同的位置,连接数据会有所不同,因此我们需要在运行时通过 vb6 代码更改此信息,以便报告指向适当的数据。这是我们使用的测试代码:
Dim nTables As Integer
Dim iCount As Integer
Dim iRitCW As Integer
'-----> Ritorno msgBox
Dim RitMsg As Integer
Dim sRitCW As String * 255
jobnum = 0
If PEOpenEngine() = False Then
MsgBox "Errore Engine"
End If
jobnum = PEOpenPrintJob("c:\test\report1.rpt")
'Declarations
Dim logonInfo As PELogOnInfo
logonInfo.StructSize = PE_SIZEOF_LOGON_INFO
logonInfo.ServerName = "dellone\sqlexpress2005" + Chr(0)
logonInfo.DatabaseName = "TEST" + Chr(0)
logonInfo.UserID = "sa" + Chr(0)
logonInfo.Password = "sasasa_2005" + Chr(0)
If (PELogOnServer("p2smon.dll", logonInfo) = False) Then
MsgBox "Connessione fallita", vbExclamation, NomeApplicazione
iRitCW = PEGetErrorCode(jobnum)
RitMsg = MsgBox("Errore n. : " + Str(iRitCW), vbExclamation, NomeApplicazione)
End
End If
nTables = PEGetNTables(jobnum)
For iCount = 0 To nTables - 1
If PESetNthTableLogOnInfo(jobnum, iCount, logonInfo, True) = False Then
MsgBox "Errore : PESetNthTableLogOn", vbExclamation, NomeApplicazione
Screen.MousePointer = 0
Exit Sub
End If
If (PETestNthTableConnectivity(jobnum, iCount) = False) Then
MsgBox ("Errore nella connessione per la tabella:" & iCount)
End If
Next iCount
If PEOutputToPrinter(jobnum, 1) = False Then
MsgBox "Stampa del documento fallita", vbExclamation, NomeApplicazione
Screen.MousePointer = 0
Exit Sub
End If
If PEStartPrintJob(jobnum, True) = False Then
MsgBox "Stampa in anteprima fallita", vbExclamation, NomeApplicazione
iRitCW = PEGetErrorCode(jobnum)
RitMsg = MsgBox("Errore di stampa n. : " + Str(iRitCW), vbExclamation, NomeApplicazione)
Exit Sub
End If
Screen.MousePointer = 0
通常在 PELogonServer 上报告的错误是 536,在 PEStartPrintJob 之后是 599。因此,我们询问我们用来初始化 logoninfo 数据结构的数据在语法上是否正确。如果必须以某种特定方式对 ServerName 字符串进行转义。我们要求确认我们在 PELogOnServer 函数中使用的 dll(“p2smon.dll”),而我们尝试使用“p2ssql.dll”以及任何可能有助于我们解决问题的进一步解释都没有成功。
提前致谢