I have to prepare a bunch of similar PDF reports.
Every report has very similar code-behind structure (aspx.vb).
I'd like to use one common code-behind (aspx.vb) file and specify DPLX-file and output file at a run-time.
When I tried, I've got 3 problems:
1. Could not load DPLX-file
2. Could not change connection string for DPLX-file
3. Could not call DrawPdfToWeb (even though I inhere ceTe.DynamicPDF.ReportWriter.DplxWebForm)
Can someone help me with code or advise?
Thanks,
Bob.
Example of my current aspx.vb-file:
____________________________________________________
Public Class Reports_DetailsOfDataImport
Inherits ceTe.DynamicPDF.ReportWriter.DplxWebForm
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Read Session and Request Parameters -------------
Dim ReportCode As String = System.Web.HttpContext.Current.Session("ReportCode")
Dim ReportSQLWhere As String = System.Web.HttpContext.Current.Session("ReportSQLWhere")
' Read Session and Request Parameters ---------end-
' Specify connection string -----------------------
Dim rpQuery As ceTe.DynamicPDF.ReportWriter.Data.Query = CType(Me.DocumentLayout.GetQueryById("Query"), ceTe.DynamicPDF.ReportWriter.Data.Query)
rpQuery.ConnectionString = "Password=" & Sec.SQLPassword() & ";Persist Security Info=True;User ID=" & Sec.SQLUser() & ";Initial Catalog=" & Sec.SQLDB() & ";Data Source=" & Sec.SQLServer()
' Specify connection string -------------------end-
' Pass parameters ---------------------------------
Parameters.Add("SqlWhere", ReportSQLWhere)
' Pass parameters -----------------------------end-
DrawPdfToWeb("DetailsOfDataImport.pdf")
End Sub
End Class
____________________________________________________
Desired aspx.vb-file, where DPLX-file and output file specified at a run-time:
____________________________________________________
Public Class AllReports
Inherits ceTe.DynamicPDF.ReportWriter.DplxWebForm
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Read Session and Request Parameters -------------
Dim ReportCode As String = System.Web.HttpContext.Current.Session("ReportCode")
Dim ReportSQLWhere As String = System.Web.HttpContext.Current.Session("ReportSQLWhere")
' Read Session and Request Parameters ---------end-
' Load DLPX specific for current Report Code ------
Dim rp As DocumentLayout = New DocumentLayout(ReportCode & ".vb.dplx")
' Load DLPX specific for current Report Code --end-
' Specify connection string -----------------------
Dim rpQuery As ceTe.DynamicPDF.ReportWriter.Data.Query = CType(Me.DocumentLayout.GetQueryById("Query"), ceTe.DynamicPDF.ReportWriter.Data.Query)
rpQuery.ConnectionString = "Password=" & Sec.SQLPassword() & ";Persist Security Info=True;User ID=" & Sec.SQLUser() & ";Initial Catalog=" & Sec.SQLDB() & ";Data Source=" & Sec.SQLServer()
' Specify connection string -------------------end-
' Pass parameters ---------------------------------
Parameters.Add("SqlWhere", ReportSQLWhere)
' Pass parameters -----------------------------end-
' Output to ReportCode-specific file name
rp.DrawPdfToWeb(ReportCode & ".pdf")
End Sub
End Class
____________________________________________________
Dynamically change DPLX file
Re: Dynamically change DPLX file
Support · Jul 17, 2007Hello,
If your code behind file inherits from ceTe.DynamicPDF.ReportWriter.DplxWebForm namespace then it is mandatory to have the name of your DPLX file same as that of your aspx page with .dplx extension. For e.g. if the name of the ASPX page is Test.aspx, then the dplx file name has to be Text.aspx.dplx.
In your case you will not inherit from the ceTe.DynamicPDF.ReportWriter.DplxWebForm namespace to dynamically change the DPLX file but inherit from the System.Web.UI.Page namespace. You will have to use the code below:
Dim report As DocumentLayout = New DocumentLayout(path to DPLX file)
Dim rp As ceTe.DynamicPDF.ReportWriter.Report = CType(Me.DocumentLayout.GetElementById("Report1"), ceTe.DynamicPDF.ReportWriter.Report)
rp.Query.ConnectionString = "dynamic connection string goes here"
Dim MyDocument As Document = return report.Run( )
MyDocument.DrawToWeb("Test.pdf")
Thanks,
ceTe Software Support Team
Re: Dynamically change DPLX file
Forum member · Jul 17, 2007Thank you for the fast response.
1. This line did not work:
Dim MyDocument As Document = return report.Run( )
Compilation Error: "Compiler Error Message: BC30201: Expression expected"
I changed it to:
Dim MyDocument As Document = New Document()
Please, correct me if I'm wrong.
2. After I corrected #1, this line did not work:
rp.Query.ConnectionString = ...
Error: "Object reference not set to an instance of an object."
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Any ideas what can be wrong with connection?
Final result with non-working connection:
____________________________________________________
Imports System
Imports ceTe.DynamicPDF
Imports ceTe.DynamicPDF.ReportWriter
Public Class ER_ReportGenerator
Inherits ceTe.DynamicPDF.ReportWriter.DplxWebForm
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Read Session and Request Parameters -------------
Dim ReportOffset As String = Request.QueryString("ReportOffset")
If ReportOffset = "1" Then ReportOffset = ""
Dim ReportCode As String = System.Web.HttpContext.Current.Session("ReportCode" & ReportOffset)
Dim ReportSQLWhere As String = System.Web.HttpContext.Current.Session("ReportSQLWhere" & ReportOffset)
' Read Session and Request Parameters ---------end-
' Create Report and change connection -------------
Dim MyReport As DocumentLayout = New DocumentLayout(Server.MapPath("./Reports_" & ReportCode & ".aspx.dplx"))
Dim rp As ceTe.DynamicPDF.ReportWriter.Report = CType(Me.DocumentLayout.GetElementById("Report1"), ceTe.DynamicPDF.ReportWriter.Report)
rp.Query.ConnectionString = "Password=" & CustomFunctions.Security.Sec2wayDecrypt(HttpContext.Current.Session("ClientSQL_Password").ToString) & ";Persist Security Info=True;User ID=" & HttpContext.Current.Session("ClientSQL_User").ToString & ";Initial Catalog=" & HttpContext.Current.Session("ClientSQL_DB").ToString & ";Data Source=" & HttpContext.Current.Session("ClientSQL_Server").ToString
' Create Report and change connection ---------end-
' Read parameters ---------------------------------
Dim parSQLWhere As String = ""
If Len(ReportSQLWhere) > 0 Then parSQLWhere = " WHERE " & ReportSQLWhere
Parameters.Add("SqlWhere", parSQLWhere)
Parameters.Add("FilterDetails", CustomFunctions.Reports.TranslateSQL2Human( ReportSQLWhere ) )
' Read parameters -----------------------------end-
' Draw result depending on Report Code ------------
'Dim MyDocument As Document = return MyReport.Run()
Dim MyDocument As Document = New Document()
MyDocument.DrawToWeb(ReportCode & ".pdf")
' Draw result depending on Report Code --------end-
End Sub
End Class
____________________________________________________
Re: Dynamically change DPLX file
Support · Jul 18, 2007Hello,
The reason you get compiled time error was because the return was keyword was not required. The correct code snippet should be as below:
Dim MyDocument As Document
Dim report = New DocumentLayout("ContactList.dplx")
MyDocument = report.Run()
The connection string can be set using the static property below:
DocumentLayout.ConnectionStrings.Add( string key, string value)
Thanks,
ceTe Software Support Team
Re: Dynamically change DPLX file
Forum member · Jul 18, 2007This line did not work:
DocumentLayout.ConnectionStrings.Add( string key, string value)
I tried:
DocumentLayout.ConnectionStrings.Add( "Query", "Password=...")
Error message: "An entry with the same key already exists."
Any ideas?
Re: Dynamically change DPLX file
Support · Jul 18, 2007Hello,
The reason you are getting the error is because the connection string entry with key equal o "Query" has already been added once and it does not allow duplicate key entry with the same name. Make sure you are using a unique key name for each instance of your DPLX file.
Thanks,
ceTe Software Support Team
Re: Dynamically change DPLX file
Forum member · Jul 18, 2007I did this intentionally, because "Query" connection defines the data source for "Report1".
As far as I understand, I have to fetch connection for a particular report, and change it.
So, I tried to use your suggestion, but it did not work.
Can you explain why would I add new connection instead of reading existing one and changing it?
How can I know that new connection is associated with "Report1"?
I may have sub-reports with different connection strings.
Re: Dynamically change DPLX file
Support · Jul 18, 2007Hello,
In your case if you wish to have different connection strings for reports and sub reports you can set them using the sample code below:
Dim layout As DocumentLayout = New DocumentLayout(MapPath("ContactListMod.aspx.dplx"))
Dim report As Report = layout.GetElementById("Report1")
report.Query.ConnectionString = "string"
Dim subReport As Report = layout.GetElementById("SubReport1")
subReport.Query.ConnectionString = "string"
When setting connection string using the Add method it takes key value pair and it does not allow you to overwrite the existing key values. That’s the reason you get the error message saying the key already exists.
Thanks,
ceTe Software Support Team
Re: Dynamically change DPLX file
Forum member · Jul 18, 2007Thank you for your fast answer.
I tried your code, unfortunately does not work again.
____________________________
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim layout As DocumentLayout = New DocumentLayout(Server.MapPath("./Reports_MyReport.aspx.dplx"))
Dim report As Report = layout.GetElementById("Report1")
report.Query.ConnectionString = "Password=..."
Dim MyDocument As Document = report.Run()
MyDocument.DrawToWeb("Test.pdf")
End Sub
____________________________
Compiler Error Message: BC30456: 'Run' is not a member of 'ceTe.DynamicPDF.ReportWriter.Report'.
------
Dim MyDocument As Document = report.Run()
------
Is it possible to get from support working example?
Maybe manual with usage examples besides those that came with the package? Maybe some code snippets developers can have access to?
I'm trying to achieve a simple task (dynamically change DPLX file + connection string) for 2 days and so far no clue how to do this. Examples simply do not work.
I expect some stupidity from my side ... but I clearly know that I have _some_ IQ (otherwise I'd not be able to type this messge :)
It is frustrating to pay 3k for the library that I don't know how to use.
Re: Dynamically change DPLX file
Support · Jul 18, 2007Hello,
It is actually just a simple typo in the code. The Run method you need is on the DocumentLayout object instead of the Report object. Here is the corrected snippet:
____________________________
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim layout As DocumentLayout = New DocumentLayout(Server.MapPath("./Reports_MyReport.aspx.dplx"))
Dim report As Report = layout.GetElementById("Report1")
report.Query.ConnectionString = "Password=..."
Dim MyDocument As Document = layout.Run()
MyDocument.DrawToWeb("Test.pdf")
End Sub
____________________________
Thanks,
ceTe Software Support Team
Re: Dynamically change DPLX file
Forum member · Jul 18, 2007Nope, this code does not work.
If you try it, you'll run on error:
"Exception Details: System.NullReferenceException: Object reference not set to an instance of an object."
Line:
report.Query.ConnectionString = "Password=..."
Re: Dynamically change DPLX file
Support · Jul 19, 2007Hello,
The error message is likely because he connection string is not getting created successfully. The same line of code works perfectly fine on our end. Can you please make sure that the variables you are retrieving to set the connection string are getting set correctly? Also please make sure that the data for the RecordBox or RecordArea you have on your DPLX file is getting returned by running the query.
Thanks,
ceTe Software Support Team
Re: Dynamically change DPLX file
Forum member · Jul 20, 2007Thank you for your patinece helping me.
The last problem was in incorrect parameter assignment.
Instead of:
DocumentLayout.ConnectionStrings.Add( string key, string value)
I had to declare parameters:
Dim MyParameters As ParameterDictionary = New ParameterDictionary()
then add parameters into my new ParameterDictionary, and then assign my ParameterDictionary to report.
After solving the problem with parameters, report generation started.