SSRS local report fails - error "An error has occurred during report processing" - reporting-services

I am running ReportViewer 10 using a local report (rdl) file in an MVC web site. I am passing in a DataSet that has the correct data with column names that match the report definition.
var reportDataSource = new ReportDataSource("dataset1", resultSet);
ReportViewer1.LocalReport.ReportPath = Server.MapPath("/Reports/Report2.rdl");
ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.LocalReport.DataSources.Add(reportDataSource);
List<ReportParameter> lst = new List<ReportParameter>();
ReportParameter rptParam1 = new ReportParameter("Id", "54");
lst.Add(rptParam1);
ReportViewer1.LocalReport.SetParameters(lst);
ReportViewer1.LocalReport.Refresh();
The error I am getting is:
I am unable to find any more specific information on the exact error.
Is there a log file somewhere I can look at?
Thank you.

it turns out that the name of the dataset must match the named defined in the report file exactly including case.
var reportDataSource = new ReportDataSource("dataset1", resultSet);
Becomes:
var reportDataSource = new ReportDataSource("DataSet1", resultSet);

Related

Unable to connect Apps Script to Cloud SQL using JDBC

So... I have been trying to set up the connection to a Cloud SQL for MySQL database from an Apps Script function, however I am unable to figure out why it is not working. I have been following the documentation for JDBC, however no matter what I do, the connection always fails.
The following is the code I am using:
const connectionName = '<project_id>:<region>:<instance_id>';
const user = '<user>';
const userPwd = '<user_pass>';
const db = '<database>';
const dbUrl = 'jdbc:google:mysql://' + connectionName + '/' + db;
function connect() {
const conn = Jdbc.getCloudSqlConnection(dbUrl, user, userPwd);
let start = new Date();
let stmt = conn.createStatement();
stmt.setMaxRows(1000);
let results = stmt.executeQuery('SELECT * FROM entries');
let numCols = results.getMetaData().getColumnCount();
while (results.next()) {
let rowString = '';
for (let col = 0; col < numCols; col++) {
rowString += results.getString(col + 1) + '\t';
}
Logger.log(rowString);
}
results.close();
stmt.close();
let end = new Date();
Logger.log('Time elapsed: %sms', end - start);
}
When running this code I get the following error:
Every time I run the code, I can see a new line in the mysqlerr logs:
I have the Cloud SQL instance set with the public IP, but I have not whitelisted any networks. The documentation does not mention it as a required step. Also I have set the project number for the GCP project of this Apps Script project, but still I get this error.
EDIT
As requested, I am adding more screenshots about the instance:
I am able to connect to the Cloud SQL instance using the gcloud sql instances connect command, and once inside I am able to query the table I want. (Bear in mind that the table is currently empty, as we are in the early stages of development at this point)
I believe this rules out the possibility of me using the wrong user/password.
As you can see I am using the default value for the max_allowed_packet flag. To be honest I have not set any flags on this instance yet.
About the connection name, I am using the format shared in the code snippet above, and actually I have copy and pasted it from the Cloud Console.
The next screenshot is the summary of the instance's settings:
Thanks in advance! šŸ˜
I work on the team that maintains Google Cloud SQL Connector libraries.
I was able to get your code sample working with my own project, so I don't think your code is the problem. The first thing I would try is double checking the values of user, userPwd, and connectionName. If those are all correct, then I would also ensure that the user you are trying to log in as has access to the database.
As for those errors you're seeing in the logs, this troubleshooting documentation has some suggestions regarding things you can try. Once suggestion would be to increase the max_allowed_packet flag
If you're sure that all of those values are correct, then please follow up to this comment and we can try to debug further.

Google App Script new editor - it shows errors in my code, but how to see what is wrong?

I am using the Google App Script new editor. I declared a variable mindt, gave it an empty string as its initial value, and assigned with a value from a query (showing below). The new editor indicated that I have an error with the new assignment statement for mindt. How can I find out why the new editor thinks I have an error? Thanks!
var maxdt = "";
... ...
var cols = rows[0].f;
mindt = cols[0].v;
You can try using console.log to print out the error
console.log(mindt)
or
Logger.log(mindt)

Select command using webmatrix

I'm using Webmatrix 3
I have the following code for obtaining session var session_username = Session["session_username"];
Now, I want to search for a username from my database like the variable session_username.
I'm using the following code to execute the query var selectcommand = "SELECT * from student where student_username = #session_username";
var row = db.Query(selectcommand);
It's giving an error Exception Details: System.Data.SqlServerCe.SqlCeException: A parameter is missing. [ Parameter ordinal = 1 ] for the line var row = db.Query(selectcommand);
What am I doing wrong? Any help?
Your code should be
var selectcommand = "SELECT * from student where student_username = #0";
var row = db.Query(selectcommand, session_username);
This tutorial explains the use of the parameter placeholders: Introduction to Working with a Database in ASP.NET Web Pages (Razor) Sites.

SQL QUERY DATA FETCH IN CRYSTAL REPORT. it only fetch first row data

var BikeOrder = (from s in dbobject.TblBikesOrders
where s.BONo == searchint
select new {s.BOId,s.BONo,}).ToArray();
rptBikeOrder rptobject = new rptBikeOrder();
rptobject.SetDataSource(BikeOrder);
crystalReportViewer1.ReportSource = rptobject;
how can i fix it. where s.BONo == searchint why not working
Put the fields in the details section of the report

how to create dynamic excel sheets based on table data

Given one table in SQL Server which holds consolidated data from three source tables including one column called OFFICE which differentiates the records from each other.
The three source tables hold data from three offices.
I want to create an Excel file dynamically which will have 3 sheets in one workbook based on the three different different offices (ex. office1, office2, office3) resulting in each sheet containing the relevant data according to its office.
Please recommend an approach using dynamic Excel destination in SSIS as I don't want to use an approach which creates a template file and then copies that template to destination excel file.
While this can be accomplished using a scipt task and C#, a far easier solution is demonstrated at
http://www.rafael-salas.com/2006/12/import-header-line-tables-_116683388696570741.html
and the follow-up
http://www.rafael-salas.com/2008/03/ssis-and-dynamic-excel-destinations_01.html#!
But to summarize the relevant details, you need to use an 'Execute SQL Task' to dynamically create the sheet at runtime prior to using it as a destination.
Create a new variable to hold the Sheet name and set this variable to the Office you are working with as you iterate through them.
Also, create a variable to hold the Create table statement that will create each sheet.
For example,
"CREATE TABLE "+ #[User::SheetName] + "(HeaderID INTEGER, HeaderName NVARCHAR(50), LineID INTEGER, LineName NVARCHAR(50), LineDetails NVARCHAR(50))"
and Set the SQLSourceType Property of the Execute SQL task inside of the For Each container to Variable and choose the Variable you created to hold the create statement.
In the Excel Destination Component, Change the data access mode to ā€˜Table Name or View Name Variableā€™ and choose the sheet name variable you created from the variable dropdown list.
I have several SSIS packages that perform a similar function. A single Excel file consists of multiple worksheets with each worksheet populated by results from a separate SQL query. Here are the basic generic steps I applied. Before you begin, make certain you create a connection manager for both the database to be applied and the output Excel file.
1) Create a Script task in Control flow and populate it like the following. Here I am creating the Excel file along with the worksheets it will contain. (Worksheets should never include any spaces or special characters.) My code below is in C#.
using System;
using System.IO;
using System.Collections.Generic;
using System.Data;
using System.Text;
using Excel = Microsoft.Office.Interop.Excel;
using Microsoft.SqlServer.Dts.Runtime;
namespace ST_87e8d62a054b4e16b60297154afc19d8.csproj
{
[System.AddIn.AddIn("ScriptMain", Version = "1.0", Publisher = "", Description = "")]
public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
{
#region VSTA generated code
enum ScriptResults
{
Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
};
#endregion
public void Main()
{
Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
object misValue = System.Reflection.Missing.Value;
xlApp = new Excel.ApplicationClass();
xlWorkBook = xlApp.Workbooks.Add(misValue);
//Create First worksheet
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
xlWorkSheet.Name = "Names";
//Define column headers for "RawData" WorkSheet
xlWorkSheet.Cells[1, 1] = "First Name";
xlWorkSheet.Cells[1, 2] = "Last Name";
xlWorkSheet.Cells[1, 3] = "Title";
// Create Second Worksheet
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(2);
xlWorkSheet.Name = "Addresses";
//Define column headers for "CCDN" WorkSheet
xlWorkSheet.Cells[1, 1] = "Street";
xlWorkSheet.Cells[1, 2] = "City";
xlWorkSheet.Cells[1, 3] = "State";
xlWorkSheet.Cells[1, 4] = "Zip";
xlWorkSheet.Cells[1, 5] = "Country";
string Filename = "C:\\MyFile.xls";
if (File.Exists(Filename))
{
File.Delete(Filename);
}
xlWorkBook.SaveAs(Filename, Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
xlWorkBook.Close(true, misValue, misValue);
xlApp.Quit();
releaseObject(xlWorkSheet);
releaseObject(xlWorkBook);
releaseObject(xlApp);
Dts.TaskResult = (int)ScriptResults.Success;
}
2) Create in your database two tables that will be populated temporarily. That is, one table will be populated for the results of the first worksheet and the second table will be populated for the results of the second worksheet. It is a good naming approach to preface the names of each table with "Working_" so that you know the purpose of each. I took the approach of using tables instead of views is because I like to sort (ORDER BY) my results, which cannot be done with a view.
3) Add to the SSIS package two Execute SQL Tasks under Control Flow. The first task will run an INSERT SQL statement that will populate the first table you just created and the second task will run another INSERT SQL statement that will populate the second table just created.
4) Add to the SSIS package two Data Flow tasks under Control Flow. The first will be for populating the first worksheet and the second for populating the second worksheet.
5) Select the first Data Flow task and add to it under Data Flow an OLE DB Source where you will define the OLE DB conenction manager (your database) and then the table or view. Select the first new table created. Make certain all of the columns of interest are selected and that you can perform a preview.
6) Add a Data Conversion flow task and then an Excel Destination flow task.
7) Repeat steps 5 and 6 for the second worksheet and table.
8) Finally under Control Flow add an Excel SQL Task that will remove the contents of the two Working tables. You do not want the old contents to be included the next time the package is run.
Now, if you want to play around with formatting of the Excel file after it is completed and impress your manager, you can also do that in code with a final Task Script (also using C#). The nice part about this approach is that you are not having to apply any special formatting functions in your SQL, Excel is doing all the work. You could actually include the formatting in Step 1 and as soon as you copy the data over in the following steps, it is automatically formatted. As with any report output, there is not point in making SQL perform formatting steps (adding additional work to the database server) when it is more efficient to let Excel or SSRS do what they do best.
public void Main()
{
Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
object misValue = System.Reflection.Missing.Value;
Excel.Range xlRange;
xlApp = new Excel.ApplicationClass();
string Filename = "C:\\MyFile.xls";
xlWorkBook = xlApp.Workbooks.Open(FileName, 0, false, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
//Format cells in Names worksheet
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
//Set the header range in bold font
xlRange = xlWorkSheet.get_Range("a1", "p1");
xlRange.Font.Bold = true;
xlRange.WrapText = true;
//Freeze first row listing headers
xlWorkSheet.Application.ActiveWindow.SplitRow = 1;
xlWorkSheet.Application.ActiveWindow.FreezePanes = true;
//Auto adjust the width of each column
xlWorkSheet.Columns.AutoFit();
xlRange = xlWorkSheet.get_Range("c1", "j6467");
xlRange.Cells.Locked = false;
xlRange.Interior.Color = 65535;
xlRange = xlWorkSheet.get_Range("o1", "p6467");
xlRange.Cells.Locked = false;
xlRange.Interior.Color = 65535;
//Do not alert when saving changes to Excel file.
xlWorkBook.Application.DisplayAlerts = false;
//Save Excel file modifications
xlWorkBook.Save();
//Close workbook and application
xlWorkBook.Close(true, misValue, misValue);
xlApp.Quit();
//Release from cache.
releaseObject(xlWorkSheet);
releaseObject(xlWorkBook);
releaseObject(xlApp);
//Set formatting of percent cells
xlRange = xlWorkSheet.get_Range("d3", "d7");
xlRange.NumberFormat = "###,###%";
//Define the top left cell and bottom right cell of the table in the Excel worksheet
xlRange = xlWorkSheet.get_Range("c1", "c7");
//Draw grid of thin line around each cell in table
xlRange.BorderAround(Excel.XlLineStyle.xlContinuous, Excel.XlBorderWeight.xlThin, Excel.XlColorIndex.xlColorIndexAutomatic, 1);
//Draw thick border around entire table
xlRange = xlWorkSheet.get_Range("a1", "d7");
xlRange.BorderAround(Excel.XlLineStyle.xlContinuous, Excel.XlBorderWeight.xlThick, Excel.XlColorIndex.xlColorIndexAutomatic, 1);
//Right justify columns B and C
xlRange = xlWorkSheet.get_Range("b3", "c7");
xlRange.HorizontalAlignment = Excel.XlHAlign.xlHAlignRight;
//Do not alert when saving changes to Excel file.
xlWorkBook.Application.DisplayAlerts = false;
//Save Excel file modifications
xlWorkBook.Save();
//Close workbook and application
xlWorkBook.Close(true, misValue, misValue);
xlApp.Quit();
//Release from cache.
releaseObject(xlWorkSheet);
releaseObject(xlWorkBook);
releaseObject(xlApp);
Dts.TaskResult = (int)ScriptResults.Success;
}
And that's about it. Notice that just for the purpose of this example, I'm hardcoding the filename. But in my actual code I am applying a User variable which is then populated by another SQL statement pulling the name from another database table. For best practices, it a good idea to keep your SSIS packages entirely table-driven. That way, any changes made to names and locations are made in a database table in a record specific to your SSIS package... avoiding any need to update your SSIS package and go through the dev to QA to production lifecycle again.
Hope this helps and please let me know if you have any questions.