This is a migrated thread and some comments may be shown as answers.

Saving Report Byte Array to Database

4 Answers 494 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Scott
Top achievements
Rank 1
Scott asked on 19 Jun 2009, 03:24 AM
I am able to create PDF's from my Telerik report very easily, and it works great.  I want to save that report to the database, so it doesn't have to regenerate every time.  It is not saving for some reason to the database, and I know that I can do this with other PDF byte arrays in other pieces of my code.  Is something different with the Telerik Byte Array?  Both below save data with other PDF byte arrays, but not the telerik report.  What am I doing wrong?  When I debug, both have values in the byte array, reportBytes.

Example 1, VB does not work: (param1 is passed in as an integer)

            Dim reportBytes As Byte()
            Dim mimeType As String = String.Empty
            Dim ext As String = String.Empty
            Dim encoding As Encoding = encoding.Default
            reportBytes = Telerik.Reporting.Processing.ReportProcessor.Render("PDF", report, Nothing, mimeType, ext, encoding)

            asqlConnection = GF_GET_DATABASE_CONNECTION()
            Dim sql As String = "UPDATE TABLE SET PDF = @reportBytes where xxx=" & CType(param1, String)
            Dim cmd As SqlCommand = New SqlCommand(sql, asqlConnection)
            cmd.Parameters.AddWithValue("@reportBytes", reportBytes)
            Dim id As Integer = cmd.ExecuteNonQuery()

Example 2, C# does not work (param1 is passed in as an integer):
            byte[] reportBytes =ReportProcessor.Render("PDF", reportToExport, null,out mimeType, out ext, out encoding);
            Database db = DatabaseFactory.CreateDatabase("ConnectionString");
            DbCommand dbCommand = db.GetSqlStringCommand("update TABLE set PDF = @imageData where xxx=" + param1);

            db.AddInParameter(dbCommand, "@imageData", DbType.Binary, reportBytes);

            int ret = db.ExecuteNonQuery(dbCommand);
            dbCommand.Dispose();

4 Answers, 1 is accepted

Sort by
0
Scott
Top achievements
Rank 1
answered on 19 Jun 2009, 03:24 AM
It says it executes the update fine, but there is nothing in the PDF column in the database
0
Steve
Telerik team
answered on 22 Jun 2009, 12:33 PM
Hi Scott,

We've answered your inquiry in the support thread you've opened.

Sincerely yours,
Steve
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Kevin
Top achievements
Rank 1
answered on 27 Jul 2015, 07:30 PM

Steve, 

  Can you please add a link to the "thread" that you inserted the comment into next time. I came here looking for an answer to the exact problem, and now I have to figure out where to head to next. Thanks.

  -Paying Customer

0
Nasko
Telerik team
answered on 29 Jul 2015, 08:50 AM
Hello Kevin,

Following is the reply from the mentioned support thread:

"We've tried the following code on our end:
using System;
using System.Text;
using Telerik.Reporting.Processing;
using Telerik.Reporting.Examples.CSharp;
using System.IO;
  
namespace ReportWriter
{
    class Program
    {
        static void Main(string[] args)
        {
            string mimeType;
            string ext;
            Encoding enc;
  
            var buffer = ReportProcessor.Render("PDF", new ProductTagReport(), null, out mimeType, out ext, out enc);
            using (var fs = File.Create(Path.ChangeExtension("ProductTag", ext)))
            {
                fs.Write(buffer, 0, buffer.Length);
            }
        }
    }
}
and the file saves as expected. So please check your SQL code as it is most likely the reason for the problem."

Additional information on the topic is available in the Exporting Report Programmatically help article.

In case you still experience any issues when saving the report as a byte array, please open a new support ticket where you can attach a sample project exhibiting the problematic behavior for review.

Regards,
Nasko
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
General Discussions
Asked by
Scott
Top achievements
Rank 1
Answers by
Scott
Top achievements
Rank 1
Steve
Telerik team
Kevin
Top achievements
Rank 1
Nasko
Telerik team
Share this question
or