我有一个用 VB.NET 编写的应用程序。 它是前一段时间为客户在 32 位架构上编写的。 数据库是MySQL 5.5。 报告是内置的 Crystal 报告,数据库连接是通过 DSN 的 ODBC 32 位 MySQL 连接器。
现在客户端已将所有客户端升级至windows 10(64bit)。 桌面应用程序与相同的旧 32 位连接器配合良好,但运行任何报告时,它都会要求登录屏幕。不幸的是,在运行时传递登录凭据不起作用。
代码如附件所示。我浏览了所有答案,但代码不起作用。我有什么遗漏的吗?有人可以帮忙吗? 我知道这个问题是一个老问题,但它是一个运行了几年的应用程序,我们真的不需要重写。
代码:(在按钮链接上调用)
Public Sub PrintAmcRemainderForIndus(ByVal componentId As Integer, ByVal AddressId As Integer)
'Dim cryRpt As New ReportDocument
Dim rPath As String = ""
Dim objForm As New frmViewReport
rPath = Application.StartupPath & "\Reports\rptAMCReminderForIndus.rpt"'
MessageBox.Show(rPath.Length & vbCrLf & rPath)
Dim crtableLogoninfos As New TableLogOnInfos()
Dim crtableLogoninfo As New TableLogOnInfo()
Dim crConnectionInfo As New ConnectionInfo()
Dim CrTables As Tables
Dim CrTable As Table
Dim TableCounter
Dim cryRpt As New rptAMCReminderForIndus()
'If you are using ODBC, this should be the DSN name NOT the physical server name. If
'you are NOT using ODBC, this should be the
'physical server name
With crConnectionInfo
.ServerName = "Indus"
'If you are connecting to Oracle there is no
'DatabaseName. Use an empty string.
'For example, .DatabaseName = ""
.DatabaseName = "indus"
.UserID = "root"
.Password = "simsoft"
End With
'This code works for both user tables and stored
'procedures. Set the CrTables to the Tables collection
'of the report
CrTables = cryRpt.Database.Tables
For Each CrTable In CrTables
crtableLogoninfo = CrTable.LogOnInfo
crtableLogoninfo.ConnectionInfo = crConnectionInfo
CrTable.ApplyLogOnInfo(crtableLogoninfo)
Next
Try
'cryRpt.Load(rPath)
Dim crParameterFieldDefinitions As ParameterFieldDefinitions
Dim crParameterFieldDefinition As ParameterFieldDefinition
Dim crParameterValues As New ParameterValues
Dim crParameterDiscreteValue As New ParameterDiscreteValue
crParameterValues.Clear()
crParameterDiscreteValue.Value = componentId
crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields
crParameterFieldDefinition = crParameterFieldDefinitions.Item("piCustomerId")
crParameterValues = crParameterFieldDefinition.CurrentValues
crParameterValues.Add(crParameterDiscreteValue)
crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)
crParameterDiscreteValue.Value = AddressId
crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields
crParameterFieldDefinition = crParameterFieldDefinitions.Item("piAddressId")
crParameterValues = crParameterFieldDefinition.CurrentValues
crParameterValues.Add(crParameterDiscreteValue)
crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)
objForm.rptViewer.ReportSource = cryRpt
objForm.Show()
Catch ex As Exception
MessageBox.Show(ex.Message & vbCrLf & ex.InnerException.Message)
End Try
End Sub
最佳答案
我想说这里有问题:
'If you are using ODBC, this should be the DSN name NOT the physical server name. If
'you are NOT using ODBC, this should be the
'physical server name
With crConnectionInfo
.ServerName = "Indus"
您确定提供的是 ODBC 名称,而不是主机名吗?
看这里:
http://www.tek-tips.com/faqs.cfm?fid=4870
这里:
How to set database login infos (connection info) for crystal report vb.net?
关于mysql - 具有用于 Crystal Reports 的 MySQL DSN 连接的 VB.NET 应用程序要求登录信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36220824/