ColdFusion Muse

Why You Should Join AA (Access Anonymous)

Mark Kruger September 22, 2006 1:43 PM Coldfusion & Databases, Coldfusion Troubleshooting Comments (1)

I'm an Access hater too - so the idea of giving tips on it galls me just a bit. Recently, however, I had the opportunity to help a fellow with his Access driven Coldfusion site. This poor soul had moved his Coldfusion site from experthost.com to godaddy.com to save a few bucks. Saving money on hosting is almost never worth it in my opinion - but I won't go there for this post. After much heartache he got the Access DSN installed using the godaddy control panel. But, uh oh... the new Access driver is the one with Unicode support (at least that's what I surmise without talking to the perky but useless godaddy support). That means that lots of things are now broken.

Broken Item 1: Permissions

In his old site he had set up his access drivers to use a username and a password. All of his queries look like this:

<cfquery name="getsomething" datasource="myDsn" username="blah" password="blah">
        SELECT someCol
        FROM    someTable
        WHERE    someThing = 'someOtherThing'        
    </cfquery>
On his old server this worked fine - even though there actually was no password attached to the db file. In his new environment, however, this generates an error: "The workgroup information file is missing or opened exclusively by another user". All of his queries had to be changed to remove the username and password.

Broken Item 2: Yes/No Field

His code is replete with queries that check Yes/No Columns. These columns are Access' equivalent of Boolean or bit columns. Most of his queries read like this:

<cfquery name="getsomething" datasource="myDsn">
    SELECT someCol
    FROM    someTable
    WHERE    myYesNo = 1
</cfquery>
A "1" being the equivalent of a "yes" and a "0" being the equivalent of a "no". Again, on his old server this was acceptable. His new server, however, doesn't see it that way - but it also doesn't throw an error. This makes it trickier because it's not immediately apparent that something is wrong. The data does not show up but the query runs successfully (or at least does not error out). To fix it we had a few choices. Where variables where in the where clause we went with the old tried and true "yesNoFormat( )" function. So this....
<cfquery name="getsomething" datasource="myDsn">
    SELECT someCol
    FROM    someTable
    WHERE    myYesNo = #yesNoVariable#
</cfquery>
...Becomes this....
<cfquery name="getsomething" datasource="myDsn">
    SELECT someCol
    FROM    someTable
    WHERE    myYesNo = #yesNoFormat(yesNoVariable)#
</cfquery>
This function produces the word "no" when it sees a zero ("0") and "Yes" when it sees any other number.

In the second case there was no variable - just a static constant in the query. In this case we simply converted the constant to an appropriate "yes" or "no" as needed. Like this:

<cfquery name="getsomething" datasource="myDsn">
    SELECT someCol
    FROM    someTable
    WHERE    myYesNo = YES
</cfquery>

Broken Item 3: The "National" Column

Finally we had a number of update and insert queries that were erroring out but we didn't know why. We finally determined that the problem was a particular Yes/No column titled "national". This column refused to recieve an update or an insert. It turns out that under the new driver, national is a keyword. So we had to change this:

<cfquery name="getsomething" datasource="myDsn">
    UPDATE     myTable
    SET        national = YES
    WHERE myField = 'something'
</cfquery>
... To This....
<cfquery name="getsomething" datasource="myDsn">
    UPDATE     myTable
    SET        [national] = YES
    WHERE myField = 'something'
</cfquery>
The brackets are qualifiers that tell the access driver to treat this as a column.

My advice to you, if you use access, is to seek help. Remember that the first step to recovery is to admit you have a problem. Meanwhile, I hope these tips help you if you ever run into this type of issue. Perhaps some of my readers can add their favorite tips to this post and further enrich our knowledge.

  • Share:

1 Comments

  • Tony Petruzzi's Gravatar
    Posted By
    Tony Petruzzi | 9/22/06 1:13 PM
    I can bet the biggest problem with moving to the new version of the driver was the plain fact that your friend doesn't use cfqueryparam. I've must of updated the JDBC drivers and the MDAC drivers a thousand times on my boxes and never had this problem with an access database.