Guest User

Untitled

a guest
Apr 16th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.80 KB | None | 0 0
  1. Dim strcon As String = ConfigurationManager.AppSettings("PhdConnectionString")
  2. Dim getconn As SqlConnection = New SqlConnection(strcon)
  3.  
  4. Dim rpt As ReportDocument = New ReportDocument
  5.  
  6. rpt.Load(Server.MapPath("aspirantCrystalReport.rpt"))
  7.  
  8. CrystalReportViewer1.ReportSource = rpt
  9. CrystalReportViewer1.DataBind()
  10.  
  11. Private Sub SetDataConnections(ByVal oReport As CRAXDRT.Report, ByVal oConnection As ADODB.Connection)
  12.  
  13. ' Do all tables in this report.
  14. Dim oTable As CRAXDRT.DatabaseTable
  15. For Each oTable In oReport.Database.Tables
  16. SetDataConnection oTable, oConnection
  17. Next
  18.  
  19. ' Find all subreports and do them too.
  20. Dim oSection As CRAXDRT.Section
  21. For Each oSection In oReport.Sections
  22. Dim oObject As Object
  23. For Each oObject In oSection.ReportObjects
  24. If TypeOf oObject Is CRAXDRT.SubreportObject Then
  25. Dim oSubreportObject As CRAXDRT.SubreportObject
  26. Set oSubreportObject = oObject
  27. SetDataConnections oSubreportObject.OpenSubreport()
  28. Set oSubreportObject = Nothing
  29. End If
  30. Next
  31. Next
  32.  
  33. End Sub
  34.  
  35. Private Sub SetDataConnection(ByVal oTable As CRAXDRT.DatabaseTable, ByVal oConnection As ADODB.Connection)
  36.  
  37. ' Extract the relevant data from the ADO connection.
  38. Dim sServer As String
  39. Dim sDatabase As String
  40. Dim bTrusted As String
  41. Dim sUserName As String
  42. Dim sPassword As String
  43. Dim nTimeout As Long
  44. With oConnection.Properties
  45. sServer = .Item("Data Source").Value
  46. sDatabase = .Item("Initial Catalog").Value
  47. Select Case UCase(.Item("Integrated Security").Value)
  48. Case "SSPI", "YES"
  49. bTrusted = True
  50. Case Else ' "NO", ""
  51. bTrusted = False
  52. End Select
  53. sUserName = .Item("User ID").Value
  54. sPassword = .Item("Password").Value
  55. End With
  56. nTimeout = oConnection.CommandTimeout
  57.  
  58. ' Delete and re-create all connection information. This is the only way of getting it
  59. ' to work if the report contains subreports. Changing database drivers on the fly is
  60. ' not allowed, so we must re-create the connection using settings appropriate for the
  61. ' particular driver involved.
  62. Select Case oTable.DllName
  63. Case "crdb_ado.dll"
  64. With oTable.ConnectionProperties
  65. .DeleteAll
  66. .Add "Database Type", "OLE DB (ADO)"
  67. .Add "Provider", "SQLOLEDB"
  68. .Add "Data Source", sServer
  69. .Add "Initial Catalog", sDatabase
  70. .Add "Integrated Security", bTrusted
  71. .Add "User ID", sUserName
  72. .Add "Password", sPassword
  73. .Add "OLE DB Services", -1
  74. .Add "General Timeout", nTimeout
  75. End With
  76. Case Else
  77. ' TODO: Handle other drivers appropriately.
  78. End Select
  79.  
  80. End Sub
Add Comment
Please, Sign In to add comment