Hi,
Is it possible now to save and load IGR reports into/from database reports in v12.1 ?
regards
Yes, it is possible, check this example.
Basically, instead of loading the report from a filestream you need to load it form a database.
Hope it helps
You can load a report from a database or any other source by loading it as a stream and providing it to the viewer.
Considering your request, you can use a Report Uri Resolver to map URI to reports and define how they are loaded (e.g. retrieve them from a DB). Here is a guide and sample to learn how to use it.
Also, if you are using client-side rendering you can do something like this to set the viewer once you have loaded the stream (e.g. retrieved from the DB).:
//Load a local report
Stream myReportStream = Application.GetResourceStream(new Uri("SilverlightApplication1;component/Report1.igr", UriKind.Relative)).Stream;
xamReportViewer1.RenderSettings = new ClientRenderSettings { DefinitionStream = myReportStream };
Hope it helps.
Regards,
Miguel
Hi, I'm affraight I can't cope with that without some help :)
I've created following code, is it correct ? I had to put the static interface which I use to get data from database:
public static IDBApi iDBApi;
public void Resolve(Uri reportUri, Action<UriResolverData> result)
{
//TODO: Add report load logic based on the reportUri parameter.
string report = iDBApi.DataBase.GetTable("select ReportBody from Reports where ReportID = 2").Rows[0][0].ToString();
var mStream =
new MemoryStream(ASCIIEncoding.Default.GetBytes(report));
result.Invoke(new UriResolverData(mStream, null));
}
Any help will be very appreciated :)
Hello,
I do apologize for not responding sooner. The code you have seems to be correct; the problem might be in the report’s igr source code. What's the error message you are getting?
Please make sure the report is being retrieved correctly from the database, if you are saving the *.igr as a string/varchar/text in the database, please compare it with the report’s source file (*.igr) to make sure they match (you can open the *.igr (xml) from the Designer by right clicking on it>Open With…).
Once you have loaded the *.igr source (xml) you can encode it and load it as you are doing it.
Here is a sample I wrote to test your scenario. I created the following SQL DB to save my reports using "id" to identify reports and saving the *.igr "as is" into "Design".
// Recognize Desired Path
if (reportUri.ToString().StartsWith(mydesiredPrefix))
// Retrieve Report igr from DB
SqlConnection connection = new SqlConnection(@"Data Source=.\sqlexpress;Initial Catalog=ReportLibraryDB;Integrated Security=True");
connection.Open();
SqlCommand command = new SqlCommand("select * from dbo.Report WHERE dbo.Report.id='Customers';");
command.Connection = connection;
SqlDataReader reader = command.ExecuteReader();
reader.Read();
// Load igr
var reportSource = reader["Design"].ToString();
connection.Close();
// Convert string to stream
byte[] byteArray = Encoding.ASCII.GetBytes(reportSource);
using (var reportStream = new MemoryStream(byteArray))
var resultUri = new UriResolverData(reportStream, null);
result.Invoke(resultUri);
else
{ // Ignore Uri Resolution
result.Invoke(null);
Hope this helps, please let me know how it goes...