CFQuery with Blank Username and Password
I am in a situation where my application may sometimes have datasources with the username and password specified, and other times needs to have the username and password specified in the CFQuery tag. The quandary being how to have one cfquery tag that supports both. The ColdFusion documentation says that the username and password in cfquery are optional, but if specified overwrite the datasource username and password. But what if they are specified blank?
It turns out that if you have nothing in the username or password, but do have them in your cfquery, then the datasource username and password is used after all.
So:
<cfset p = "">
<Cfquery name="getstuff" datasource="#application.datasourcename#" username="#u#" password="#p#">
Select RecordA, RecordB, Record_Blah
From MyTBL
</Cfquery>
Works just fine against a datasource that has the user/pass already defined and putting in the user and pass will satisfy the other need as well.
Like this entry? Subscribe to my blog.


Comments (moderation on)
There are no comments for this entry.
[Add Comment]