Datasource verification failed error

465 views
Skip to first unread message

Mohamad El-Husseini

unread,
Jan 27, 2011, 1:08:23 PM1/27/11
to ColdFusion on Wheels
I just wrote a query in cfscript, and it's causing this weird error:

"Datasource testdatasource verification failed.
The root cause was that: java.sql.SQLException: Usernames and
Passwords for all the database tags within the cftransaction tag must
be the same. "

Here's my custom function (I omitted params). It lives in Post.cfc
model, and it's called from Vote.cfc model via a callback:

public void function updateScore(required numeric postId, required
numeric amount)
{
local.post = new
Query(datasource=variables.wheels.class.connection.datasource);
local.post.setSQL("UPDATE posts SET posts.score = posts.score
+ :amount WHERE posts.id = :postId");
local.post.execute();
}

Here's the callback in Vote.cfc:

private boolean function updatePostOnCreate()
{
return this.post().updateScore(this.postId, 1);
}

The relationships are set correctly, too:

belongsTo("post");

afterCreate("updatePostOnCreate");
afterUpdate("updatePostOnUpdate");

Mohamad El-Husseini

unread,
Jan 27, 2011, 1:16:04 PM1/27/11
to ColdFusion on Wheels
FYI... the function works fine if it's not called from a callback...

Why would the callback cause this? There's something about
cftransaction tags not using the same datasource name and password in
the cftransaction tag.... I don't know what that's about!

tpet...@gmail.com

unread,
Jan 27, 2011, 2:56:47 PM1/27/11
to ColdFusion on Wheels
the reason is because callback are wrapped within the transaction,
while just being called from a function isn't.

on to the error at hand. the only reason i can think that you're
getting this is because you set the dataSourceUserName and
dataSourcePassword in your config/setting.cfm. if those are set then
wheels will pass the username and password to the datasource with
every call.

when dealing with transactions, you have to pass the exact same
credentials with every call. so let's say you have the following two
cfquery calls:

query 1 you pass datasource, username, password
query 2 you just pass the datasource

since the credentials are different, you get the error that you're
getting. however if you do:

query 1 you pass datasource, username, password
query 2 you pass datasource, username, password

or

query 1 you just pass datasource
query 2 you just pass datasource

then everything works just fine.

that said, you have two options to fix this:

1) in your updateScore() method, pass in the datasource, username,
password arguments to the query call
2) remove the dataSourceUserName and dataSourcePassword in config/
settings.cfm and subsequent environment config files

Chris Peters

unread,
Jan 27, 2011, 1:31:23 PM1/27/11
to cfwh...@googlegroups.com
Are you setting dataSourceUsername and dataSourcePassword in your config file? If you're not doing the same in your Query object instantiation, then it will complain.

Callbacks are called within the same cftransaction as the main query that you're running.


--
You received this message because you are subscribed to the Google Groups "ColdFusion on Wheels" group.
To post to this group, send email to cfwh...@googlegroups.com.
To unsubscribe from this group, send email to cfwheels+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/cfwheels?hl=en.


Mohamad El-Husseini

unread,
Jan 27, 2011, 3:00:13 PM1/27/11
to ColdFusion on Wheels
Chris, I have set a username and password in my config file. I guess I
will have to set them in the function too...

Thanks for the explanation. It makes sense now.

On Jan 27, 1:31 pm, Chris Peters <ch...@clearcrystalmedia.com> wrote:
> Are you setting dataSourceUsername and dataSourcePassword in your config
> file? If you're not doing the same in your Query object instantiation, then
> it will complain.
>
> Callbacks are called within the same cftransaction as the main query that
> you're running.
>
> On Thu, Jan 27, 2011 at 1:16 PM, Mohamad El-Husseini
> <abitdo...@hotmail.com>wrote:
> > cfwheels+u...@googlegroups.com<cfwheels%2Bunsubscribe@googlegroups.c om>
> > .

William Fisk

unread,
Jan 27, 2011, 4:31:09 PM1/27/11
to cfwh...@googlegroups.com
Just a question, why would you set the username and password in the config file.  I always set it in the CF administrator and that's it.  Isn't that safer and simpler?

Mohamad El-Husseini

unread,
Jan 27, 2011, 4:45:02 PM1/27/11
to ColdFusion on Wheels
@William, I had no idea. I thought it's the standard way to do it, to
be honest. Now that you mention it, that does make more sense.

@Tony, thanks for the explanation earlier!
Reply all
Reply to author
Forward
0 new messages