EasyCFM.COM ColdFusion Forums / ASP to CFML / help converting ASP to CFML - connection code

   Reply to Discussion | New Discussion << previous || next >> 
Posted By Discussion Topic: help converting ASP to CFML - connection code -- page: 1 2 3

book mark this topic Printer-friendly Version  send this discussion to a friend  new posts last

MikeCFM7
03-02-2007 @ 12:45 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
New Member
Posts: 22
Joined: Mar 2007

I need nelp in connecting to an Access Database Using File DSN and Coldfusion.  I have an example of how to code ASP but don't know how to convert the code to CF.  Also, I don't know what forum to post this in.  Here is the ASP example code that I need to convert to CF:
<%
Dim oConn, oRs
Dim qry, connectstr, sDSNDir
Dim db_name, db_username, db_userpassword
Dim db_server, dsn_name

dsn_name = "your_dsn_name"
fieldname = "your_fieldname"
tablename = "your_tablename"

sDSNDir = Server.MapPath("_dsn")

connectstr = "filedsn=" & sDSNDir & "/" & dsn_name

Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open connectstr
qry = "SELECT * FROM " & tablename

Set oRS = oConn.Execute(qry)

if not oRS.EOF then
while not oRS.EOF
response.write ucase(fieldname) & ": " & oRs.Fields(fieldname) & " "
oRS.movenext
wend
oRS.close
end if

Set oRs = nothing
Set oConn = nothing

%>
I have Coldfusion setup with GoDaddy and I have a DSN and file name for my Access Database.  I use the Developers edition of Coldfusion with Macromedia Dreamweaver 8.

You are appreciated.
Mike

You are appreciated.
Mike

You are appreciated.
Mike

JJfutbol
03-02-2007 @ 1:06 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Moderator
Posts: 1250
Joined: Nov 2004

Ah good ol' ASP. Smile  I remember those days. There's little to no trouble in converting what you have. I take it, as you stated, you not only have the DSN setup but know what the DSN is. In this case the only other thing you need to know is the cfquery tag.

Within the starting and closing cfquery tag you specify your SQL code. You can see the documentation for it here: http://www.cfquickdocs.com/?getDoc=cfquery. Assuming you don't have to use a username and password to interact with your database (godaddy would have given this to you if so) then all you have to specify is the datasource attribute along with a name for the query. For example:

<cfquery name="qUsers" datasource="your-DSN-goes-here">
SELECT userId, username
FROM users
</cfquery>

And that's all there is to it. Simple no? Again note there is a username and password attribute for the cfquery tag. I'm not sure if godaddy requires that you specify that as well. Most ISP's don't, just using the DSN is enough. If you do need to specify the username and password you would have something like this:

<cfquery name="qUsers" datasource="myDSN" username="myDsnUsername" password="myDsnPassword">...

----------------------------------------------------
Some free CF applications available at my site, such as the popular CFC Validator www.javier-julio.com My new site design is up!! Let me know what you all think! Working on a fully accessible Forum, which validates as full CSS and XHTML 1.0 Strict.

mquack
03-02-2007 @ 2:08 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Moderator
Posts: 1544
Joined: Jan 2005

Mike, welcome to EasyCFM.  PLEASE read the forum guidelines before continuing your use of the forums.  You've posted the identical message in three places.  This is absolutely and completely unacceptable.  We don't have very many rules here, so we'd certainly appreciate it if you have the decency to follow the few we do have.

Thanks.

www.rachelqueensg.com
Amazon Wish List

MikeCFM7
03-06-2007 @ 1:57 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
New Member
Posts: 22
Joined: Mar 2007

Please accept my apology.  It won't happen again.
It seems I have sufficiently displayed my novice-ness.  In addition, I failed to check the appropriate check boxes in easycfm so only today did I discover I had answers.
On the plus side, I do learn from my mistakes.
Thanks for setting me straight and again, forgive me for violating the rules.

You are appreciated.
Mike

JJfutbol
03-06-2007 @ 2:02 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Moderator
Posts: 1250
Joined: Nov 2004

Don't worry about it Mike, mquack is just tough on the new guys. You know how it is. Some express their care for others with tough love. He's a great guy and you'll find he's very active here. Smile  Definitely pay heed to any advice he gives. Let us know how you are doing. Very glad to see you are moving from ASP to CF. You'll love working with it.

----------------------------------------------------
Some free CF applications available at my site, such as the popular CFC Validator www.javier-julio.com My new site design is up!! Let me know what you all think! Working on a fully accessible Forum, which validates as full CSS and XHTML 1.0 Strict.

mquack
03-06-2007 @ 2:18 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Moderator
Posts: 1544
Joined: Jan 2005

Mike,

No problem.  Glad to have you aboard, and, like JJ said, there are lots of people here who love to help people get "unstuck".


www.rachelqueensg.com
Amazon Wish List

MikeCFM7
03-06-2007 @ 2:21 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
New Member
Posts: 22
Joined: Mar 2007

I had my EasyCFM setup wrong (contact boxes unchecked) so I just discovered I had an answer.

Thank you so much for answering.  What you gave me is very helpful.  I am trying to use Ben Forta's book (construction kit for cf mx7)to learn but it would help a lot if I can get connected to my access database on GoDaddy.

I will try the query you suggested but do I need an application.cfc(or cfm?) in my online directory and if so what should it contain?  I found it in Forta's book but don't quite understand it.

I am using Macromedia Studio 8 and cfmx7 developer edition.

Thanks again, you may be the "lifeline" to keep me from drowning in all the cf code.  Wink

You are appreciated.
Mike

mquack
03-06-2007 @ 2:26 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Moderator
Posts: 1544
Joined: Jan 2005

Ben's WACK is definitely an invaluable resource.  Perfect for the "beginner", and perfect for the "experienced" as well.

To connect a datasource, you just need to make sure that it is setup on your account first.  This might require you to contact GD's support, or it might be something you can do in your account's control panel.  Not familiar with their hosting, so I'm not sure on that.

You don't need an Application.cfc/cfm to connect to a database, no.  But you'll need one of the two for handling sessions or anything like that.  What about it are you specifically having troubles with?


www.rachelqueensg.com
Amazon Wish List

MikeCFM7
03-06-2007 @ 3:26 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
New Member
Posts: 22
Joined: Mar 2007

Using code from an online developer I made and then ftp'd using Dreamweaver, an application.cfm "<cfset datasource = "database_01"> using the DSN I had setup on GoDaddy for the 'database_01'"
I then made a query on an index.cfm page "<cfquery datasource="datasource" name="GetBible1">
SELECT ID
FROM tbl_Bible1
WHERE ID=2
</cfquery>
I ftp'd this page and when run I get a cf error "database not found" or some words to that effect.

I asked GoDaddy to check and see if I had the database setup right and they said "Dear Mike,

Thank you for contacting Online Support.

Customer support cannot provide tutorial or troubleshooting information regarding third party scripts or applications. We recommend referring to the application documentation or online community for further resolution. We apologize for any confusion."

Now I am stuck.  I keep experimenting with different code but I don't understand the concept of connecting to GoDaddy.  
I can see they have added a directory called Access_db so I uploaded my mdb file to that directory but I don't know if that is the correct way to do it.  I tried moving it to my site root directory but still get the not found error.

It is likely a problem with my own ignorance of cf but I can't seem to picture the process in my mind.

Thank you for your help!



You are appreciated.
Mike

mquack
03-06-2007 @ 3:32 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Moderator
Posts: 1544
Joined: Jan 2005

LOL!  Nice support they have going on there... WOW!

So, when you setup your DSN, did it give you a confirmation message letting you know that it successfully connected to your database?

I'm going to say that if they had a directory named Access_db, that you should place your .mdb file in that directory.

Also, please copy/paste the exact error message that CF displays.

www.rachelqueensg.com
Amazon Wish List

PAGE: 1 2 3

Website Designed and Developed by Pablo Varando.