0

Crystal Reports를 처음 사용했습니다. 코드를 통해 런타임에 보고서의 데이터 소스를 설정해야합니다. 나는 작동 코드가 있지만 예측할 수 없으며 많은 문제를 일으키고있다. 나는 단지 내가 잘못한 일을하고 있는지 또는 이것을하기위한 더 좋은 방법이 있는지 알고 싶었습니다.크리스탈 리포트에 프로그래밍 방식으로 데이터베이스 연결을 설정하는 방법

때로는 보고서가 독립형 Crystal 응용 프로그램의 보고서 컴파일 시간에 지정된 연결을 사용하는 대신 연결 문자열을 사용하지 않는다고 생각합니다. 사실입니까?

Dim connectionInfo As New ConnectionInfo 

     connectionInfo.ServerName = "UID=abc;PWD=abc;Driver= {SQL Server};Server=" & Page.Request.QueryString("server") & ";Database=" & Page.Request.QueryString("database") 

Using report As New ReportDocument 
      report.Load(Server.MapPath("/report/Crystal/test.rpt")) 
      report.FileName = Server.MapPath("/report/Crystal/test.rpt") 

      SetDBLogonForReport(connectionInfo, report) 
... 
End Using 

    Private Sub SetDBLogonForReport(ByVal connectionInfo As ConnectionInfo, ByVal reportDocument As ReportDocument) 

     Dim tables As Tables 
     tables = reportDocument.Database.Tables 

     For Each table As CrystalDecisions.CrystalReports.Engine.Table In tables 

      Dim tableLogonInfo As New TableLogOnInfo 

      tableLogonInfo = table.LogOnInfo 
      tableLogonInfo.ConnectionInfo = connectionInfo 
      table.ApplyLogOnInfo(tableLogonInfo) 

     Next 


    End Sub 
+0

어떤 오류가 발생합니까? 웹에 예제를 통해 DB에 보고서를 연결하는 방법을 보여주는 예제가 많이 있습니다. –

답변

2

이것은 이전에 물어 보았지만, 다른 사람들이 답변을 찾고있는 경우 여기에 응답을 게시 할 것이라고 생각했습니다. 방금 위 코드를 사용했는데 몇 가지 예외는 있지만 잘 작동했습니다. New TableLogOnInfo을 루프의 변수를 초기화 tableLogonInfo, 또한

connection.DatabaseName = [DatabaseName] 
connection.UserID = [UserID] 
connection.ServerName = [ServerName] 
connection.Password = [Password] 

불필요 :

connectionInfo.ServerName = [Entire ConnectionString?] 

에 :

는 I 변경됨.

위의 설명에서 언급했듯이 많은 예제가 있습니다. 솔루션을 검색 할 때 처음 도착한 결과이기 때문에 여기에 답변을 추가한다고 생각했습니다.