Reputation: 75
I'm working with ColdFusion 11 and am getting an error with cftransaction. I'm not sure what causing it.
I have two CFC's: abc.cfc and xyz.cfc. abc.cfc
does not use the datasource attribute: as it is defined in the Application.cfc using this.datasource
.
Here is the error:
Error! The root cause was that: java.sql.SQLException: Usernames and Passwords for all the database tags within the cftransaction tag must be the same. Datasource inventorymgt verification failed.. Entry rolled back
What I am doing is:
<cftransaction action="begin">
<cftry>
<cfscript>
f = structNew();
f.companyName = '#arguments.structform.companyname#';
f.address = '#arguments.structform.address#';
f.settingsID = arguments.structform.settingsID;
r = tblUpdate('settings',f);
sresult = 'Updated';
</cfscript>
<cfset str = "Cool! Settings has been " & sresult>
<cftransaction action="commit"/>
<cfcatch type="any">
<cftransaction action="rollback"/>
<cfset str = "Error! #cfcatch.Detail# #cfcatch.Message#. Entry rolled back">
</cfcatch>
</cftry>
</cftransaction>
And another CFC which is expecting the init function like the datasource, username,password is using the following query way to update it:
<cfquery name="q"
datasource="#variables.dbsource#"
username="#variables.dbuname#"
password="#variables.dbpword#">
Upvotes: 1
Views: 594
Reputation: 141
I think the reason is explained in this post: https://groups.google.com/forum/#!topic/cfwheels/AZTvxvhsapc
Within a cftransaction tag, every query has to use the same authentification. You cannot have one query use a datatasource and the other use a username and password within the same transaction.
I would agree with the author of the link. I always just define the datasource once in the cf-administrator, so I don't have to deal with username/password. Then you can initialize your cfc just by datasource.
I don't know what your function tblUpdate is actually doing, but might be that you use a different syntax than in the query you posted? Because, that's what your error code says:
Usernames and Passwords for all the database tags within the cftransaction tag must be the same.
Upvotes: 1