sid not returned by cfprocparam that is connected to oracle database - sql

The application in question runs on Coldfusion 11 with hotfix 7 and running on a Linux server that is connected to a Windows Oracle database. The goal is to make the application run on Linux which is a step by step process (which is why the database in on Windows server).
I know the database works because it connects successfully via the Coldfusion administrator panel and this SQL statement returns an user_id successfully:
<cfquery name="qUser" datasource="#Application.datasource#">
SELECT td_user_id
FROM td_user
WHERE ROWNUM <= 1
</cfquery>
The code in question is such:
<cfstoredproc procedure="td_session_pkg.new_session" datasource="#application.datasource#">
<cfprocparam type="In" cfsqltype="CF_SQL_CHAR" value="#arguments.username#">
<cfprocparam type="In" cfsqltype="CF_SQL_CHAR" value="#arguments.password#">
<cfprocparam type="In" cfsqltype="CF_SQL_CHAR" value="#cgi.remote_addr#">
<cfprocparam type="In" cfsqltype="CF_SQL_INTEGER" value="#rand_int#">
<cfprocparam type="In" cfsqltype="CF_SQL_INTEGER" value="#application.app_id#">
<cfprocparam type="In" cfsqltype="CF_SQL_INTEGER" value="1">
<cfprocparam type="In" cfsqltype="CF_SQL_INTEGER" value="#pwdRequired#">
<cfprocparam type="Out" cfsqltype="CF_SQL_CHAR" variable="sid">
</cfstoredproc>
<!--- Test --->
<cfquery name="testS" datasource="#Application.datasource#">
SELECT
sys_context('USERENV','SID') AS theSid
FROM dual
</cfquery>
<cfthrow message="SID: #sid# and #testS.theSid#">
The cfthrow returns
SID: (blank here) and 37
I've had tried many things but have yet to return the sid correctly (it is needed to continue user authentication). The values inside the cfprocparam tags are variables stated above and all have valid values.
Coldfusion variables are not case sensitive, as stated by Adobe
Any insight as to why this wouldn't return the sid and why the SQL statement would? (from my research I believe they are the same thing).
Thanks for the help, I am will and answer any questions quickly.

Since the code I posted in comments has the white-space mangled:
SET SERVEROUTPUT ON;
DECLARE
sid VARCHAR2(20);
BEGIN
td_session_pkg.new_session(
'username',
'password',
'remote_addr',
0,
0,
1,
0,
sid
);
DBMS_OUTPUT.PUT_LINE( 'SID' || sid );
END;
/
Run this in an SQL client (i.e. SQL developer or SQL/Plus) from the user you would connect to via ColdFusion.
The aim is to test that the database:
Has the procedure.
The database user has access to it.
The procedure runs in the database.
The procedure gives the expected result.
Running the query successfully will tell you that #1-#3 are fine and you can check #4 against your expectations.
If any aren't as expected then you know the problem is at the database end and not in ColdFusion.
If they run as expected then you can start looking at the CF settings to make sure your datasources are pointing where you expect (i.e. are they connecting to the correct user) and that the datasource has permissions to execute procedures.
Then if that is all correct, look at the variables you are passing into the <CFSTOREDPROC> and <CFPROCPARAM> tags - are the datasource and variables as expected.
If you want to formalize it as you go then you could write unit & integration tests which cover the steps you try and next time you want to test things you just run the test suites.

Related

SQL Server job error on email notification

I have configured a database email, operators, and such on my SQL managed instance, to receive an email when a job fails.
In the email, we get something like this "The yyy_job failed on step 3".
But my question is... Is there a way to add the error message on the body of the email? I've been searching for this, but can't fine a suitable answer.
Thank you in advance
As far as I know there's no way to add further details to the email notifications when a job fails.
The only way is to implement your own notification process.
https://www.sqlshack.com/reporting-and-alerting-on-job-failure-in-sql-server/
We have a similar set up. We have a SQL Server Agent job that consists of several steps.
I configured it in such a way that we receive notification email when the job starts and another email when it finishes. There are two versions of the final email - one for success, another for failure.
At the end of the job there are two final steps called "Email OK" and "Email FAIL". Note how each of the steps have their "On Success" and "On Failure" configured.
This is how "Email OK" and "Email FAIL" steps look like in our case:
In my case I simply have different subjects of the emails, so it is easy to filter in the email client.
You can write any extra T-SQL code to execute a query against msdb.dbo.sysjobhistory and include the relevant result into the email.
I will not write a complete query here, but I imagine it would look similar to my sketch below. If you need help with that, ask another question.
This is how you can use msdb.dbo.sp_send_dbmail to include the result of some query into the email text:
EXEC msdb.dbo.sp_send_dbmail
#profile_name = 'ABC'
,#recipients = 'abc#example.com'
,#subject = 'Some subject line'
,#body = #VarBody
,#body_format = 'TEXT'
,#importance = 'NORMAL'
,#sensitivity = 'NORMAL'
,#query = N'
-- show latest entry in the log for your job
SELECT TOP(1)
message, ...
FROM
msdb.dbo.sysjobhistory
WHERE
job_id = ''your job ID''
ORDER BY
instance_id DESC;
'
,#execute_query_database = 'msdb'
;
Have a look at the documentation for a list of parameters for sp_send_dbmail. Example above inlines the query result. You can also attach it as a separate file.

Coldfusion cfqueryparam - changing encoding?

When running a query with EncryptByKey and cfqueryparam, the value appears to be getting truncated.
For example:
<cfset customer_number = 123 />
<cfset soc_sec_number = "123-45-6789" />
<cfquery datasource="web_applications">
OPEN SYMMETRIC KEY SSNKey
DECRYPTION BY CERTIFICATE SSNCert;
UPDATE
Customers
SET
SSN_Encrypted = EncryptByKey( Key_GUID( 'SSNKey' ), <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#soc_sec_number#" > )
WHERE
customer_number = <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#customer_number#" > ;
CLOSE SYMMETRIC KEY SSNKey;
</cfquery>
The resulting database value, when decrypted, is "1". If I remove the <cfqueryparam>, the whole value is stored without issue. Additionally, this issue only occurs when used in conjunction with EncryptByKey.
We're using CF 2018 and sql 2016. This just began to be a problem yesterday. It may or may not be related, but our power was lost yesterday. Is is possible that some cf file was corrupted, or some encoding setting was changed? How would I check for this?
UPDATE:
When performing the following query:
<cfquery name="get_ssn">
OPEN SYMMETRIC KEY SSNKey
DECRYPTION BY CERTIFICATE SSNCert;
SELECT
CONVERT( VARCHAR, DecryptByKey( [ssnEncrypted] ) ) AS decrypted_ssn
FROM
customers
WHERE
Customer.customer_number= <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#customer_number#" > ;
CLOSE SYMMETRIC KEY SSNKey;
</cfquery>
The resulting value of decrypted_ssn is as follows:
<cfdump var="#get_ssn.decrypted_ssn#"> -> 123-45-6789
<cfdump var="#right(get_ssn.decrypted_ssn, 4)#"> -> 89
in sql studio -> 1
I suspect some encoding issue at this point, since coldfusion returns the full value but thinks that right(123-45-6789, 4) is 89 rather than 6789
I'm not sure how to test this theory.
UPDATE:
I've confirmed this issue is arising on more than one table, and with more than one symmetric key.
UPDATE again:
The string saved using cfqueryparam, when the LEN() command is used, outputs 22, whereas the value WITHOUT cfqueryparam outputs 11.
UPDATE:
I followed the solution Here, which seemed to resolve my issue. But I want to understand how this happened. The connection didn't seem to require this until yesterday, when the power went out and the server restarted.

Column name or number of supplied values does not match table definition

i had a stored proc for which i made changes and added 2 new form fields to a stored proc
and then ran it successfully
now when i revoke the stored proc and run , it runs successfully but in the coldfusion
it gives the error
[Macromedia][SQLServer JDBC Driver][SQLServer]Insert Error: Column name or number of supplied values does not match table definition.
90 : <cfprocparam type="in" cfsqltype="CF_SQL_INTEGER" dbvarname="#reportMonth" value="#xxMDB#">
91 : <cfprocparam type="in" cfsqltype="CF_SQL_INTEGER" dbvarname="#orderBy" value="#xxOBDB#">
92 : **<cfprocresult name="xxResult">**
93 : </cfstoredproc>
Since ColdFusion MX:
Changed the dbvarname attribute
behavior: it is now ignored for all
drivers. ColdFusion uses JDBC 2.2 and
does not support named parameters.
http://www.cfquickdocs.com/cf8/#cfprocparam

Element RECORDCOUNT is undefined in "yyReslt"

I have a query that is being used in a coldfusion file (MX)( on the Production since 10 yrs ).
I have used this application/files since 4 months,successfully.
But now ,Suddenly I am getting the error
Element RECORDCOUNT is undefined in "yyReslt"
Will this occur if the Database connection is slow/improper?
Are there any conditionals around the cfquery? Are you sure it is being ran? You should turn on debugging for your IP address to make sure the query is running.
Also, you would get a different error if the connection timed out.
Sounds like your query might have some cfif statements in/around it, and nothing is being done. In addition to what Jason mentioned, you can also use cfdump to view the query object on your screen without turning on the debug data.
<cfdump var="#yyReslt#">
This also could be a concurrency issue combined with unscoped variables if happening within the context of a component that exists in the application scope, but the query variable was not scoped within the component.
<cfcomponent>
<cffunction name="foo">
<cfquery name="yyReslt" datasource="DB">
SELECT ...
</cffunction>
<cfif yyReslt.RecordCount GT 1>
.... DO SOME WORK ....
</cfif>
</cfcomponent>
simply scoping yyReslt at the before the query would fix this.
<cfset var yyReslt = "" />
All variables need to be scoped, varscoper is helpful in checking components for scoping omissions.
http://varscoper.riaforge.org/

Accessing RAISEERROR message from cfstoredproc

I have a SQL stored procedure which under some situations will return a result of -1 if it fails, but also returns a message via the RAISERROR command e.g.:
BEGIN
RAISERROR ('Error %i has occurred', 11, 1, 0)
RETURN -1
END
I am accessing this via coldfusion using cfstoredproc e.g.:
<cfstoredproc procedure="sp_return" datasource="myDatasource" returncode="yes">
<cfdump var="#cfstoredproc#">
But the structure returned only contains an ExecutionTime and StatusCode keys. Is there any way I can access the error message which has been returned. e.g. To display to the user.
Thanks,
Tom
p.s. I would tag with "cfstoredproc" but I can't create new tags.
Not sure what DB you use but with Oracle I just use ColdFusion Exceptions to bubble up the Oracle exceptions. - #cfcatch.message# and #cfcatch.detail# are what you want to echo to the user.
<cftry>
<cfstoredproc procedure = "my_Proc" dataSource = "#DB#" returnCode = "No">
<cfprocparam type="in" cfsqltype="CF_SQL_VARCHAR" variable="myvar" value="#someval#" null="No">
<cfprocresult name="my_Response">
</cfstoredproc>
<cfcatch type="any">
<cflog file="ProcError" text="Message = #cfcatch.message# Detail= #cfcatch.detail#">
</cfcatch>
</cftry>
Have you tried cfprocresult? Manual page says:
Associates a query object with a
result set returned by a stored
procedure.