Execute Store Command Entity Framewrok - asp.net-mvc-3

Hello I am using Entity Framework and I am using the ExecuteStoreCommand to do a query against the database. well I am basically calling a user defined function.
This is the call:
string result = m.ExecuteStoreQuery (SQL).FirstOrDefault();
I query the User Defined Function and I get the following result.
2.09,2.06,2.06,2.0098,2.04,2.04,2.04,2.04,2.04,2,2.1,2.04,2.04,2.04
The return type for the user defined function is
RETURNS Varchar(200). The result above is from the same cell.
When I execute the code from MVC controller I get the following error.The data reader has more than one field. Multiple fields are not valid for EDM primitive types.
What datatype I should be using instead of string.
Any ideas and suggestions.

Apparently, the return type is not only a string.
On the SQL Server side, try to surround the code of your query with:
SET NOCOUNT ON
<your current sql code>
SET NOCOUNT OFF
Maybe EF is getting the rows affected in the result and gets messed up.

Related

How to pass table as a input parameter in function?

Is it possible to pass table as input parameter in Monetdb function/procedure?
I tried prepare statement but was not able to get it working.
Also it would be nice to get statementid returned directly by 'prepare' statement rather then query sys.prepared_statements
No, you cannot pass (table) identifiers to functions/procedures.
You could use this trick, but I wouldn't recommend it for production use.

User-Defined Function Nested in Macro - Framework Manager

We are trying to create a dynamic query subject filter. To do this, we are trying to nest an Oracle user-defined function inside of a macro.
Example query subject filter:
#strip(ORACLE_USER_DEFINED_FUNCTION())#
We have imported the oracle function ORACLE_USER_DEFINED_FUNCTION into Framework Manager. The function returns a VARCHAR2 of the desired expression. For testing purposes, this function is simply returning VARCHAR2 value of '1=1' (the single quotes are not part of the VARCHAR2 return value).
The idea being that we want the query subject filter expression to be dynamically generated at run-time so the resulting query contains '...WHERE 1=1'. The strip macro is the mechanism to pre-process and invoke the user-defined function before the query is sent to the database.
However, when attempting to verify/check the query subject filter we receive the following error.
XQE-GEN-0018 Query Service internal error has occurred, please see the log for details.
I'm trying to get a hold of the query service log, but don't yet have it.
Perhaps there is some casting needed to convert the oracle VARCHAR2 output from the function to an IBM/Cognos string that is acceptable input for the IBM/Cognos macro.
Your assistance is appreciated. Thanks in advance.
Using Oracle 12c and Cognos 11.1.
With the exception of the queryValue macro function, macros are evaluated prior to accessing the database. This means the macro does not know what the Oracle UDF is or what its supposed to do. If you are able to call the UDF via a FM query subject you maybe able to get away with something similar to the queryValue answer found here:
Cognos 11.1.7 Framework manager change the table for the query subject, type data

OLE DB connection in SSRS doesn't like when parameters are repeated

I'm changing an Oracle based SSRS report and I'm having all sorts of issues with parameters.
The connection to Oracle is OLE DB.
My code is not doing anything complicated. I've only added in a new parameter. When I only have one instance of said parameter, it runs without any issues. As soon as I add it again, it bombs.
What I'm trying to do is show records if a parameter has a match. If no match, show all records.
I can run both queries in DBVisualizer without any issues.
This is what I've done
WHERE FieldName = nvl(:parameter, FieldName)
This one doesn't return the same results as this below
WHERE FieldName = :parameter
OR :parameter IS NULL
Problem is the second WHERE clause will not run in SSRS with an OLE DB connection. We cannot use another connection manager, unfortunately.
EDIT: Thanks to Hannover Fist, I was able to get this to work by doing this
I changed my WHERE clause to
WHERE FieldName = :parameter
OR :parameter2 IS NULL
Then mapped parameter2 to pull from the same SSRS parameter as the original parameter
I haven't found a good solution to this problem but I have worked around it by declaring the parameter in the Oracle SQL and mapping it to the SSRS parameter.
Then use the parameter created in the Oracle SQL in the rest of the query. This way you'll only use each SSRS parameter once.

How do I set an SSRS Parameter that doesn't have a value to something else?

I have an SSRs Report with a parameter that gets information from SQL. If it hasn't found anything, at the moment it is just empty. Is there anyway to set it such that if it's empty it will return a different value, say "Please Extend Date Ranges" and disable the parameter?
If you using it to fill it using the SQL and using it for only internal purposes then there is option to make the parameter internal and it will be hidden and it will does not prompt the user.
Make a change to the stored procedure or query that populates the parameter. Include some logic so that if no results are returned by the query you are using now, it adds a row with the default label you want.
But no, you can't disable the parameter dynamically, I don't believe.

ServiceNow Encoded Query validation

I intend to let users specify encoded query in ServiceNow SOAP requests.
The problem is that if user specifies invalid query string (e.g. "?##" or "sometext"), ServiceNow do not return any exception, but every row or no rows at all.
Is there a way to check validity of encoded query via webservice?
Fandic,
If you know ahead of time which table the SOAP query will be running against (or can get that information from the user when they submit the query) you can set up your own web service exclusively for checking the validity of a query string.
GlideRecord has the "addedEncodedQuery" method for putting in encoded queries, and it has a getEncodedQuery for turning the current query into an encoded string. If you instantiate a GlideRecord object, and pass it an invalid query string like this:
var myGR = new GlideRecord('incident');
myGr.addEncodedQuery('invalid_field_foo=BAR');
You can then call getEncodedQuery out to see if it is valid:
var actual_query = myGR.getEncodedQuery(); //sys_idNotValidnull
You shouldn't do simple comparison between the input and the output, as the API doesn't guarantee that a valid query will be returned as the exact same string as entered. It's better to simply validate that the actual_query does not equal 'sys_idNotValidnull'.
I always recommend enabling the system property 'glide.invalid_query.returns_no_rows' to avoid this effect. The property does just what it says. I never understood why you'd ever want to return all rows for an invalid query. I've seen a number of cases where developers had a query defect and never knew it since rows were coming back.
You can use the below code so that query will return the result only when it correct.
gs.getSession().setStrictQuery(boolean);
This overrides the value of system property :
glide.invalid_query.returns_no_rows
Reference : https://docs.servicenow.com/bundle/istanbul-platform-administration/page/administer/reference-pages/reference/r_AvailableSystemProperties.html
Check the property value glide.invalid_query.returns_no_rows. If it's true, the invalid query returns no rows. If false (or not available) it is ignored.
This can be overridden with gs.getSession().setStrictQuery(boolean); on a script-by-script basis.

Resources