Querying two datasources (MS ACCESS)

Ask a Question related to Coldfusion Database Access, Design and Development.

  1. #1

    Default Querying two datasources (MS ACCESS)

    Using a database that holds the job ticket information, I need to create an
    email notification checking against a different database (employee table) to
    see if the employee is set to receive notificaitons. I have the <cftransaction>
    tag and it said only one datasource could be used within the tags. I removed
    it, but was still unable to get it to work. I would get a ''notify'' variable
    undefined, except that all fields are populated in the database.


    <cftransaction>
    <cfif AddRecord is "yes"><!--- Add New Ticket --->
    <cfif #trim(nombre)# is not "">
    <cfif #trim(emailto)# is not "">
    <CFQUERY NAME="#Table_Name#_Insert_Query" DATASOURCE="HelpDesk">
    INSERT Into #Table_Name# (Entry_Date, Priority_Level, Status,
    Entry_Description, Name, Type, Location, Emailto, DueDate)
    VALUES ('#Entry_Date#', '#Priority_Level#', '#Status#',
    '#Entry_Description#', '#nombre#',
    <cfif #trim(Type)# is "">Null
    <cfelse>'#Type#'
    </cfif>,
    <cfif #trim(Location)# is "">Null
    <cfelse>'#Location#'
    </cfif>, '#emailto#','#DueDate#')
    </cfquery>
    <!--- WORKING ON EMAIL NOTIFICATIONS TO VOLUNTEERS --->

    <cfset volunteer = "#emailto#">

    <cfquery name = "notifyon" datasource="emp">
    select fname, notify
    from emptbl
    where email = '#volunteer#'
    </cfquery>
    <cfif notify is "Yes">
    <cfmail to = "#checkmail#" from = "HelpDesk@FirstBankAK.com" subject =
    "#nombre# has created a ticket for your issue" server = "10.1.100.202">
    #fname#, you have requested assistance from the Help Desk regarding the
    following:
    #Entry_Description#

    A ticket has been created by #nombre# to address your issue.
    </cfmail>
    </cfif>

    RuBot Guest

  2. Similar Questions and Discussions

    1. Problem querying Access DB for records within a certaindate range.
      Hi Everyone, I'm having a problem pulling records out of an Access DB that are between a certain date range. The records are located in a...
    2. Querying two datasources, but how?
      Datasource HelpDesk - Tables: HelpDeskList A, Volunteers B, Datasource Employee - Tables: Employee C. A.Emailto, A.Entry_ID, A.Name B.Name,...
    3. MS Access datasources stopped working
      Using CF MX 6.0 Developer Edition on Windows 2000 Pro, SP4, I was able to create a MS Access datasource. After upgrading to CF MX 6.1(server...
    4. querying field / column names in Access table
      I got great info on my last post, so let's try this one and see if my luck is still good: I have an Access table with about 30+ columns / fields...
    5. Exception error querying Access database from ASP page... Memo field type?
      Hi! Working with an MS Access database from an ASP webpage and I'm getting an Exception error... Error Type: (0x80020009) Exception...
  3. #2

    Default Re: Querying two datasources (MS ACCESS)

    Try the attached code.

    The main thing is to scope the query variables "qVolunteerDetails...." etc.

    Also note that I've removed some excessive # symbols added a few more trims,
    etc.

    Regards,
    -- MikeR


    <CFIF AddRecord is "yes"><!--- Add New Ticket --->
    <CFIF Trim (nombre) is not ""> <!--- Nombre should be trimmed below,
    too. --->
    <CFIF Trim (emailto) is not "">
    <CFSET volunteer = Trim (emailto)>

    <CFQUERY name="#Table_Name#_Insert_Query" datasource="HelpDesk">
    INSERT INTO
    #Table_Name#
    (
    Entry_Date,
    Priority_Level,
    Status,
    Entry_Description,
    Name,
    Type,
    Location,
    Emailto,
    DueDate
    )
    VALUES
    (
    '#Entry_Date#',
    '#Priority_Level#',
    '#Status#',
    '#Entry_Description#',
    '#nombre#',
    <CFIF Trim (Type) IS ""> NULL <CFELSE>'#Trim
    (Type)#' </CFIF>,
    <CFIF Trim (Location) IS ""> NULL <CFELSE>'#Trim
    (Location)#' </CFIF>,
    '#volunteer#',
    '#DueDate#'
    )
    </CFQUERY>


    <!--- WORKING ON EMAIL NOTIFICATIONS TO VOLUNTEERS --->

    <CFQUERY name="qVolunteerDetails" datasource="emp">
    SELECT fname,
    notify <!--- Is notify string or boolean? --->
    FROM emptbl
    WHERE email = '#volunteer#'
    </CFQUERY>

    <CFIF qVolunteerDetails.RecordCount NEQ 1>
    <CFOUTPUT> <h1>Oopsie!</h1> </CFOUTPUT>
    <CFABORT>
    </CFIF>

    <CFIF qVolunteerDetails.notify>
    <CFMAIL
    to = "#checkmail#"
    from = "HelpDesk@FirstBankAK.com"
    subject = "#nombre# has created a ticket for your issue"
    server = "10.1.100.202"
    >
    #qVolunteerDetails.fname#, you have requested assistance
    from the Help Desk regarding the following:
    #Entry_Description#

    A ticket has been created by #nombre# to address your
    issue.
    </CFMAIL>
    </CFIF>

    MikerRoo Guest

  4. #3

    Default Re: Querying two datasources (MS ACCESS)

    Thank you so much!
    RuBot Guest

  5. #4

    Default Re: Querying two datasources (MS ACCESS)

    Oh yeah, one thing: I had this segment within <cftransaction> tags. It happened
    to prevent the record from being added if there was an error within the tags, I
    believe. Having two datasources, I had to remove the <cftransaction> tags. Is
    there a workaround for this?

    RuBot Guest

  6. #5

    Default Re: Querying two datasources (MS ACCESS)

    Originally posted by: RuBot
    Oh yeah, one thing: I had this segment within <cftransaction> tags. It
    happened to prevent the record from being added if there was an error within
    the tags, I believe. Having two datasources, I had to remove the
    <cftransaction> tags. Is there a workaround for this?

    IMO, this is not a situation where you would need a CFTRANSACTION. You
    already know the "volunteer" email, and you are not inserting/updating the
    "emptbl". Just perform the "qVolunteerDetails" query first and show an error
    message if the volunteer record was not found. Otherwise, perform the INSERT
    and then CFMAIL (if needed).


    mxstu Guest

  7. #6

    Default Re: Querying two datasources (MS ACCESS)

    I'm not exactly sure where or what it was since I'm continually making so many
    changes here and there, but I do know that when I have some errors, the record
    will still be inserted.

    Is there any way to get around this?

    RuBot Guest

  8. #7

    Default Re: Querying two datasources (MS ACCESS)

    Well, what I'm saying is that in this case I think you should control the
    INSERT with CFIF statements instead of CFTRANSACTION. IMO, CFTRANSACTION is
    not warranted here.

    Based on your code, you should ...
    - First verify that the selected "volunteer" exists in the "emptbl" table
    - If the "volunteer" was not found, display an error message and do NOT
    perform the INSERT
    - Otherwise, perform the INSERT and CFMAIL (if needed)

    You don't want to use CFTRANSACTION as some sort of global CFM error handler
    or undo-button ;-) It is intended for use with multiple database queries. When
    you use CFTRANSACTION, some level of database locking is involved, so you
    should keep your CFTRANSACTION blocks as brief as possible and omit any code
    that is unrelated to the database queries involved.

    This article provides some good information about using CFTRANSACTION:
    [url]http://www.macromedia.com/devnet/mx/coldfusion/articles/cftransaction.htm[/url]



    <!---- psuedo-code ----->

    <!--- Ensure that the "volunteer" exists --->
    <CFQUERY name="qVolunteerDetails" ...>
    ... your SELECT statement here
    </CFQUERY>

    <!--- If the volunteer was not found, do NOT perform the INSERT --->
    <CFIF qVolunteerDetails.RecordCount EQ 0>
    ... Display your error message here ....
    <CFELSE>
    <CFQUERY name="yourInsertQuery" ...>
    ... your INSERT statement here....
    </CFQUERY>

    <CFIF qVolunteerDetails.notify>
    <CFMAIL ... >.....</CFMAIL>
    </CFIF>
    </CFIF>

    mxstu Guest

  9. #8

    Default Re: Querying two datasources (MS ACCESS)

    Yeah that makes sense, but I'm wondering this (first groggy thought of the
    workday)

    this doesn't protect against a syntax error or invalid data entry somewhere
    right? because I think that's where I'm having the problems.

    RuBot Guest

  10. #9

    Default Re: Querying two datasources (MS ACCESS)

    No, but you should be designing your code to prevent forseeable or common
    errors and handle unexpected errors (i.e. use validation on form or url
    variables, use cfqueryparam in queries, use cftry/cfcatch blocks).

    In any case, I do not think that is an issue here. With the new CFIF
    structure, if there is a syntax error in the INSERT query nothing will be
    inserted and the page will abort.

    mxstu Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139