위로 Crystal Reports가 여전히 ActiveX를 지원하는 경우 ODBC 데이터 원본이 Access 또는 SQL 데이터베이스를 가리 키도록 작성된 수정 보고서가 있습니다. 런타임에는 ODBC 대신 OLE DB (ADO)를 사용하도록 보고서를 변경하고 서버 이름, 데이터베이스 이름, 사용자 이름, 암호를 사용자 고유의 것으로 변경하고 보고서를 실행하여 정상적으로 작동합니다.코드에서 Crystal Reports 연결 속성을 변경하는 방법은 무엇입니까?
Crystal Reports 2008에서는 ActiveX를 더 이상 지원하지 않으므로 .NET에서는 똑같은 작업을 수행하려고하지만 성공하지는 못합니다.
다음은 지금까지 코드 : 그것은) (boReportDocument.VerifyDatabase 할 때까지Public Function ChangeConnectionInfo() As ReportDocument
Dim boReportDocument As New ReportDocument
'**EDIT** Change the path and report name to the report you want to change.
boReportDocument.Load("c:\CustomerListSQL.Rpt", OpenReportMethod.OpenReportByTempCopy)
'Create a new Command Table to replace the reports current table.
Dim boTable As New CrystalDecisions.ReportAppServer.DataDefModel.CommandTable
'boMainPropertyBag: These hold the attributes of the tables ConnectionInfo object
Dim boMainPropertyBag As New PropertyBag
'boInnerPropertyBag: These hold the attributes for the QE_LogonProperties
'In the main property bag (boMainPropertyBag)
Dim boInnerPropertyBag As New PropertyBag
'Set the attributes for the boInnerPropertyBag
boInnerPropertyBag.Add("Auto Translate", "-1")
boInnerPropertyBag.Add("Connect Timeout", "15")
boInnerPropertyBag.Add("Data Source", "K2")
boInnerPropertyBag.Add("General Timeout", "0")
boInnerPropertyBag.Add("Initial Catalog", "DBNAME")
boInnerPropertyBag.Add("Integrated Security", "True")
boInnerPropertyBag.Add("Locale Identifier", "5129")
boInnerPropertyBag.Add("OLE DB Services", "-5")
boInnerPropertyBag.Add("Provider", "SQLOLEDB")
boInnerPropertyBag.Add("Tag with column collation when possible", "0")
boInnerPropertyBag.Add("Use DSN Default Properties", "False")
boInnerPropertyBag.Add("Use Encryption for Data", "0")
'Set the attributes for the boMainPropertyBag
boMainPropertyBag.Add("Database DLL", "crdb_ado.dll")
boMainPropertyBag.Add("QE_DatabaseName", "DBNAME")
boMainPropertyBag.Add("QE_DatabaseType", "OLE DB (ADO)")
'Add the QE_LogonProperties we set in the boInnerPropertyBag Object
boMainPropertyBag.Add("QE_LogonProperties", boInnerPropertyBag)
boMainPropertyBag.Add("QE_ServerDescription", "K2")
boMainPropertyBag.Add("QE_SQLDB", "True")
boMainPropertyBag.Add("SSO Enabled", "False")
'Create a new ConnectionInfo object
Dim boConnectionInfo As New CrystalDecisions.ReportAppServer.DataDefModel.ConnectionInfo
'Pass the database properties to a connection info object
boConnectionInfo.Attributes = boMainPropertyBag
'Set the connection kind
boConnectionInfo.Kind = CrConnectionInfoKindEnum.crConnectionInfoKindCRQE
'**EDIT** Set the User Name and Password if required.
'boConnectionInfo.UserName = "UserName"
'boConnectionInfo.Password = "Password"
'Pass the connection information to the table
boTable.ConnectionInfo = boConnectionInfo
'Get the Database Tables Collection for your report
Dim boTables As CrystalDecisions.ReportAppServer.DataDefModel.Tables = _
boReportDocument.ReportClientDocument.DatabaseController.Database.Tables
'For each table in the report:
' - Set the Table Name properties.
' - Set the Command table's command text.
' - Set the table location in the report to use the new modified table
For Each boReportTable In boTables
boTable.Name = boReportTable.Name
boTable.QualifiedName = "DBNAME.dbo." + boReportTable.Name 'boReportTable.QualifiedName
boTable.Alias = boReportTable.Alias
boReportDocument.ReportClientDocument.DatabaseController.SetTableLocation(boReportTable, boTable)
Next
'Verify the database after adding substituting the new table.
'To ensure that the table updates properly when adding Command tables or Stored Procedures.
boReportDocument.VerifyDatabase()
Return boReportDocument
End Function
코드는 작동, 나는 오류 '실패에 로그인'은을 얻을 때 그건. 중 하나가 작동하지 않았다
Dynamically change the connection of a Crystal Report
, 나는 그것이 OLE DB에 ODBC에서 전환과 관련이 있는지 여부 (ADO)를 모르는 :
은 나뿐만 아니라 여기에 코드를 사용하여 시도
어떤 생각을? – Mzn
ServerName 속성은 "192.168.1.1,1234"를 받아 들여야합니다. 여기서 1234는 포트 번호입니다. IP/서버 이름 뒤에 콜론을 적어 둡니다. – KalaNag