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:

view plain print about
1<cfset u = "">
2<cfset p = "">
3<Cfquery name="getstuff" datasource="#application.datasourcename#" username="#u#" password="#p#">
4Select RecordA, RecordB, Record_Blah
5From MyTBL
6</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.

TweetBacks
Comments (Comment Moderation is enabled. Your comment will not appear until approved.)

NAVIGATION

Home
About Me

RSS


Search

Subscribe

Enter your email address to subscribe to this blog.

Recent Entries

Google TV Review
Playbook - Developers It's Time To Get Started
cf.Objective 2011 - Speak Your Mind
Timesheets, Project Management, and Invoicing - FreshBooks Review
A New Phase of My Life

Recent Comments

FireFox 3.6 KTML Editor Fix
Herman said: Hello, Sinds Firefox 10 is out the filebrowser in KTML and CSS Styles are not avaible... Any sugges... [More]

OTA OK?
AnoraDD said: I get 18 of these exact sms's everyday! How do I get it to STOP?!? [More]

Coldfusion Hosting with Network Solutions
LIzm said: Ugh. I have a client who insists on hosting with them and two weeks after first contact, a very simp... [More]

IE nested list item whitespace solution: vertical-align:bottom
Lauren said: Thought I'd add to the thank yous... Thank you! [More]

OTA OK?
Rita said: Thank you, this was very helpful. [More]

Calendar

Sun Mon Tue Wed Thu Fri Sat
   1234
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29    

Archives By Subject

blogs (31) [RSS]
books (4) [RSS]
Consulting (2) [RSS]
Crazy (39) [RSS]
DIY (8) [RSS]
Flex (3) [RSS]
games (10) [RSS]
GRRR (13) [RSS]
Ideas (11) [RSS]
Local (15) [RSS]
LOLpics (2) [RSS]
money (9) [RSS]
music (3) [RSS]
Personal (28) [RSS]
Photos (8) [RSS]
Politics (8) [RSS]
Projects (22) [RSS]
Review (20) [RSS]
RPM (9) [RSS]
Spam (16) [RSS]
Technology (69) [RSS]
Testing (3) [RSS]
TV (15) [RSS]
video (32) [RSS]
Web Dev (230) [RSS]
World of Warcraft (16) [RSS]