Report column is showing #Error when using Subscriptions - subscription

As titled, when using SSRS 2017 subscriptions to generate a report, a column with expression is showing #Error. However, when I try to run manual in web and in the report builder, it can be shown.
The Expression is:
=Code.Decode(Fields!Comments.Value)
The function is:
Function Decode(ByVal EncodedString AS String) AS String
Return System.Web.HttpUtility.HTMLDecode(EncodedString)
End Function
Any suggestion or help will be welcome.

I resolve the problem by myself. Use the following method instead
Function Decode(ByVal EncodedString AS String) AS String
Return System.Net.WebUtility.HtmlDecode(EncodedString)
End Function

Related

SQL Server 2012 assembly execution failure - System.NullReferenceException: Object reference not set to an instance of an object

I am trying to execute a UDF which uses a CLR assembly. Each time I try to run it I get the below error:
Msg 6522, Level 16, State 1, Line 45
A .NET Framework error occurred during execution of user-defined routine or aggregate "Geocode":
System.NullReferenceException: Object reference not set to an instance of an object.
at ProSpatial.UserDefinedFunctions.GeocodeUDF(SqlString countryRegion, SqlString adminDistrict, SqlString locality, SqlString postalCode, SqlString addressLine)
It is a geocoding assembly, which is based on the below blog:
https://alastaira.wordpress.com/2012/05/04/geocoding-in-sql-server-with-the-bing-maps-locations-api/
Is there anything I can do to fix it? It was working fine, but just stopped working recently. I changed the Bing Maps key to a new one, but that hasn't resolved the issue. Anyone have any ideas?
Cheers
Edit: I entered a formatted URL into Chrome, to see if I can get the error. I entered the below URL format:
http://dev.virtualearth.net/REST/v1/Locations?countryRegion={0}&adminDistrict={1}&locality={2}&postalCode={3}&addressLine={4}&key={5}&output=xml
All I did was to replace items 0 to 5 with their respective entries. I left the curly brackets in there, and then also tried it without the curly brackets. Without the curly brackets, the URL returned a result with no issues.
In the browser, I am getting geocoded results, but not in SQL any more
Just worked it out. One of the address fields that was being geocoded was null in the database, and the API did not like that. So I removed that from the geocoding list
Looking at the code in that blog, if you are passing in a NULL, then it's not the API that's throwing the error. The error is happening because NULL values are not being handled when the method is first called. The code just casts the SqlString input parameters to string without first checking to see if there is a value in the SqlString variable. SqlString is very similar to a nullable string.
Fortunately, it is rather easy to adjust the code to properly handle NULL values in the input parameters. Starting with a redacted snippet of the original code below, I will show how to do this for one parameter and you can repeat that modification for the others (well, the ones that might actually be NULL in the DB; no need to do this for parameters that are guaranteed to be there due to being in a NOT NULL column).
public static SqlGeography GeocodeUDF(
SqlString countryRegion,
SqlString adminDistrict,
SqlString locality,
SqlString postalCode,
SqlString addressLine
)
{
...
string localAdminDistrict = string.Empty;
if (!adminDistrict.IsNull)
{
localAdminDistrict = adminDistrict.Value;
}
// Attempt to geocode the requested address
try
{
geocodeResponse = Geocode(
(string)countryRegion,
localAdminDistrict,
(string)locality,
(string)postalCode,
(string)addressLine
);
}
All I did was:
Added a local variable for localAdminDistrict, defaulted to an empty string.
Added an if block to set localAdminDistrict if adminDistrict is not null.
Updated the call to Geocode() to use localAdminDistrict instead of (string)adminDistrict.
This should work as long as the Bing Maps API is ok with an empty value for adminDistrict (i.e. ...&adminDistrict=&locality=... ), as opposed to adminDistrict not being present in the GET request (which is easy enough, it just requires an additional modification).
ALSO: As long as you are going to be in there updating the code, you really should move the calls to the Close() and Dispose() methods into a finally block for that try / catch.
For more info on working with SQLCLR in general, please visit: SQLCLR Info

Simplejdbccall Stored Procedure withNamedBinding true

I want to execute stored procedure with dynamic parameters with SimpleJdbcCall. In total I have 6 optional parameters in SQL server SP, out of them I must be able to pass any or none. My SP executes fine as expected in MS Studio. But not by SimpleJdbcCall. I tried in many ways and one of them I tried is withNamedBinding. But it gives Input Syntax error near "=" as below.
this.simpleJdbcCall = new SimpleJdbcCall(jdbcTemplateObject)
.withNamedBinding()
.withSchemaName("dbo")
.withProcedureName("EmployeeDetails")
.useInParameterNames(
paramNameArray)
.returningResultSet("detailReportData", BeanPropertyRowMapper.newInstance(Employee.class));
Map<String,Object> out = this.simpleJdbcCall.execute(sqlSource);
Log:
2019-01-31 18:14:49 DEBUG SimpleJdbcCall:405 - The following
parameters are used for call {call dbo.EmployeeDetails(empCode => ?,
empName => ?, empLoc => ?)} with {empCode=0, empName='hgkghdkgf',
empLoc='kjhjk'} 2019-01-31 18:14:49 DEBUG DispatcherServlet:993 -
Could not complete request
org.springframework.jdbc.UncategorizedSQLException:
CallableStatementCallback; uncategorized SQLException for SQL [{call
dbo.EmployeeDetails(empCode => ?, empName => ?, empLoc => ?)}]; SQL
state [S0001]; error code [102]; Incorrect syntax near '='.; nested
exception is com.microsoft.sqlserver.jdbc.SQLServerException:
Incorrect syntax near '='.
I had faced similar type of problem and found few solutions in this stack overflow question. But in my case I was using MS-SQL server and it was giving me this same syntax error. While searching for solutions I came across this example of Spring (See Section 11.5.6. Declaring parameters to use for a SimpleJdbcCall).
Just in case if the link becomes unavailable, here is what it says
We can opt to declare one, some or all of the parameters explicitly. The parameter metadata is still being used. By calling the method withoutProcedureColumnMetaDataAccess we can specify that we would like to bypass any processing of the metadata lookups for potential parameters and only use the declared ones. Another situation that can arise is that one or more in parameters have default values and we would like to leave them out of the call. To do that we will just call the useInParameterNames to specify the list of in parameter names to include.
And here is the sample code
public class JdbcActorDao implements ActorDao {
private SimpleJdbcCall procReadActor;
public void setDataSource(DataSource dataSource) {
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
jdbcTemplate.setResultsMapCaseInsensitive(true);
this.procReadActor =
new SimpleJdbcCall(jdbcTemplate)
.withProcedureName("read_actor")
.withoutProcedureColumnMetaDataAccess()
.useInParameterNames("in_id")
.declareParameters(
new SqlParameter("in_id", Types.NUMERIC),
new SqlOutParameter("out_first_name", Types.VARCHAR),
new SqlOutParameter("out_last_name", Types.VARCHAR),
new SqlOutParameter("out_birth_date", Types.DATE)
);
}
// ... additional methods
}
I am not sure why but the withNamedBinding() method seems to not work properly with ms-sql server and creates the syntax error.
So in the above solution the work around is to
not to use the .withNamedBinding() method.
use the .withoutProcedureColumnMetaDataAccess() method.
while passing your parameter array to the .useInParameterNames() method, make sure you pass it in the sequence it is declared in the proc (as we are not using name binding). My out parameter was declared few parameters before the last one and so it was giving me error while converting var to int as my out param was int.
So now your solution should look something like this :
this.simpleJdbcCall = new SimpleJdbcCall(jdbcTemplateObject)
.withSchemaName("dbo")
.withProcedureName("EmployeeDetails")
.withoutProcedureColumnMetaDataAccess()
.useInParameterNames(paramNameArray)
.returningResultSet("detailReportData", BeanPropertyRowMapper.newInstance(Employee.class));
Map<String,Object> out = this.simpleJdbcCall.execute(sqlSource);
Give it a try and see if this works for you.

JOOQ: 3.10.5 concat string value with field

I'm new to JOOQ and using the latest version of JOOQ (3.10.5).
I am using it just as a SQL builder and not executing it against any DB.
I created the DSLContext using
Connection creatorConn = null;
creator = DSL.using(creatorConn, SQLDialect.MYSQL_8_0);
When i tried to concat an arbitrary String 'CC_' with a qualified field name field("TBL.[COLUMN NAME]") then resulting field is like
'CC'_ || "TBL.[COLUMN NAME]"
Then, when i use getSQL(), i got something like
select concat(?, TBL.[COLUMN NAME])
Can someone please tell me what went wrong and why is it the string concatenated has been replaced with a ?.
As per the solution posted here by Lukas Eder
I just added the
ParamType.INLINED to the Query.getSQL()
method which resolved this issue. Thanks

SSRS expression for empty parameter value returns #Error

I have a parameter in report that I recently changed it to accept NULL values. It was a required parameter before but now it is not required. Header in the report has below expression to read data from the parameter value. Ever since I modified the parameter to accept NULLvalues, it is erroring out. It shows #Error in the header. I have tried modifying the expression to display result even if the parameter is 'NULL', but nothing has worked so far. I am pretty much stuck here. Here is the expression I am using in SSRS:
=IIF(Code.MultipleValues(Parameters!ProductID.Value(0))="True"
,IIF(IsNothing(First(Fields!ProductName.Value, "ProductHeader")),""
,First(Fields!ProductName.Value, "ProductHeader")).ToString
,IIF(Len(Parameters!ProductID.Value(0)) > 0
,IIF(First(Fields!ProductName.Value, "ProductHeader") is nothing,""
,First(Fields!ProductName.Value, "ProductHeader")),"All Products Selected"))
I believe the error has to do with the VB custom code that is in the report. I am not too familar with the code so I am having trouble troubleshooting it.
VB code:
Public Function MultipleValues(ByVal str As String) As String
If str.Contains(",")
Return "True"
Else
Return "False"
End If
End Function
Any suggestion on how to handle #Error in SSRS? thanks
Replace
Code.MultipleValues(Parameters!ProductID.Value(0))="True"
with
IndexOf(Parameters!ProductID.Value(0).ToString(),",") >= 0
Instead of a function, can you just put the IsNothing check in front of the parameter ?
=IIF(Code.MultipleValues(IsNothing(Parameters!ProductID.Value(0),""))="True"

change image in report builder using iif function

I'm working with sql server report builder and I'm trying to change the value of an image according to a chosen date from a parameter.
I've selected external as source and in the expression window I have something like this:
=iif(Parameters!Date.Value <> 11.04.2013, "http://rack.0.mshcdn.com/media/ZgkyMDEyLzEyLzA0L2I1L3doZXJlZG9nb29nLmJoTi5qcGcKcAl0aHVtYgk5NTB4NTM0IwplCWpwZw/4931e287/304/where-do-google-doodles-come-from--ff2932470c.jpg", " ")
but I receive the following message:
Argument not specified for parameter 'TruePart' of 'Public Function IIf(Expression As Boolean, TruePart As Object, FalsePart As Object) As Object'.
I'm pretty new to work with the report builder, so please someone help me find out the solution.
I pasted your expression into a sample report set up with a parameter Date, data type Date/Time, and got the same error when using the expression.
I resolved this by changing the data being compared to the parameter in the expression into a string that can readily be converted to a date, so from 11.04.2013 to "11-Apr-2013":
=iif(Parameters!Date.Value <> "11-Apr-2013", "http://rack.0.mshcdn.com/media/ZgkyMDEyLzEyLzA0L2I1L3doZXJlZG9nb29nLmJoTi5qcGcKcAl0aHVtYgk5NTB4NTM0IwplCWpwZw/4931e287/304/where-do-google-doodles-come-from--ff2932470c.jpg", " ")
This stopped the error occurring for me and worked as expected when I selected different dates; i.e. the URL on all dates except 11-Apr-2013.

Resources