Question

Creating an ODBC connection to an access database

Asked by: rudodoo

How would I create an ODBC connection to an Access database using coldfusion?

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2006-03-26 at 19:40:35ID21789749
Tags

odbc

,

connection

,

access

,

database

Topics

ColdFusion Application Server

,

ColdFusion Studio

Participating Experts
4
Points
500
Comments
32

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. ODBC
    What is ODBC and how do you use it. Do you know of any good web sites that I can get an overview of ODBC.
  2. ODBC
    when I connect to Access by using ADO, In windows 98 I connect through DNS ( cn.Open "DSN=myconnection" ), but in windows 2000 when i go to control panel, i could not find ODBC. How can I connect or where i can find ODBC in 2000
  3. DSN connection to an access databas
    I need example code of how to connect(through DSN)to an access databas(access 2000). I need too to show information from this databas(e.g economy.mdb) in text fields in a form. P.S. I know how to create the data name source through the control panel in windows.Thanks.
  4. Excel and ODBC
    Hello VBA Experts, I'm writting an application using VBA in Excel. Currently, I have been asked to connect the application to a MySQL databae using ODBC to retireive information. As far as I know this is possible for SQL Server, Oracle, MS Access and CSV and TXT files. Is...
  5. ODBC
    Can you govern ODBC connections through AD? I.e. only allow an administrator to establish the connection? Is this common practice?

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: pinaldavePosted on 2006-03-26 at 22:22:15ID: 16297945

     
Setting up the database


The first step in your application is to set up the database. This example uses a Microsoft Access database, but any database will work with the schema you create here. There are actually two steps involved:

1      Create the database.
2      Set up the data source.

Read more : http://www.macromedia.com/devnet/dreamweaver/articles/webservice_07.html

------------------------------------------------------
Another good tutorial:
http://www.peachpit.com/articles/article.asp?p=29452&rl=1

 

by: rudodooPosted on 2006-03-26 at 22:27:58ID: 16297954

what if the database is on a remote server

 

by: rudodooPosted on 2006-03-26 at 22:39:22ID: 16297992

because I have set up the database but I always get this error

 Cannot start your application. The workgroup information file is missing or opened exclusively by another user.
 

 

by: Mr_NilPosted on 2006-03-27 at 00:53:48ID: 16298553

rudodoo,

This is the third time you've asked the same question.
Your original question is here : http://www.experts-exchange.com/Web/WebDevSoftware/ColdFusion/Q_21788441.html#16288140

When I get a chance I will work out exactly what you need to do and post the answer there, unless someone else has the opportunity before me.

 

by: rudodooPosted on 2006-03-27 at 01:07:15ID: 16298624

Thank you

 

by: dgrafxPosted on 2006-03-27 at 05:42:03ID: 16299995

<cftry>
<cfquery dataSource="#Request.Datasource#" name="Test">
SELECT *
FROM YourTable
</cfquery>
<cfcatch>
<cfdump var="#Error#">
</cfcatch>
</cftry>

Datasource OK

 

by: rudodooPosted on 2006-03-27 at 07:10:54ID: 16300812

I took out the <cfdump var="#error#"> and just put
<cf dump var="error" because it wasn't working correctly the other way.  However now it says that I have a

 Element RECORDCOUNT is undefined in TESTSEARCH.

Could you take a look at my code and see if there are some modifications that need to be made

<!--- Get mls list from database --->
<cfif isDefined("FORM.submit")>
<cftry>
<cfquery name="testsearch"  datasource="#Request.DSN#" username="userid" password="passcode">
SELECT mls.mlsid, mls.city, mls.state, mls.zip, mls.area, mls.price, mls.listing,
(SELECT TOP 1 mlspicpath FROM TblPicPaths WHERE mlsid = mls.mlsid) AS mlspicpath
FROM MLS
Where 0=0
<!---Search by mlsid or text fields--->
<cfif Form.mlsid IS NOT "">
AND mls.mlsid LIKE '%#FORM.mlsid#%'
</cfif>
<!---Search by CITY or list fields--->
<cfif Form.city is not "">
and mls.city = '#Form.city#'
</cfif>
<!--- search by state --->
<cfif Form.state is not "">
and mls.state = '#Form.state#'
</cfif>
<!--- Select zip --->
<cfif Form.zip is not "">
and mls.zip like '%#form.zip#%'
</cfif>
<!--- select area --->
<cfif Form.area is not "">
and mls.area ='#form.area#'
</cfif>
<!--- select price--->
<!--- select min price--->
<cfif Form.min_price is not "">
and mls.price >=#form.min_price#
</cfif>
<!--- select max price--->
<cfif Form.max_price is not "">
and mls.price <=#form.max_price#
</cfif>
<!---select listing--->
<cfif form.listing is not "">
and mls.listing ='#form.listing#'
</cfif>
</cfquery>
<cfcatch>
<cfdump var="#Error#">
</cfcatch>
</cftry>
</cfif>

 

by: rudodooPosted on 2006-03-27 at 07:12:12ID: 16300825

Don't Forgot to change the <cfdump var="#Error#"> to <cfdump var="Error">

 

by: rudodooPosted on 2006-03-27 at 07:16:59ID: 16300870

But on the other hand if you leave the ## variable tags in their I get an error saying that it is undefined

 

by: dgrafxPosted on 2006-03-27 at 07:31:14ID: 16301017

Looking back at your question - I think I posted in the wrong question or something ???
I could have sworn your question was How to determine if datasource if configured or setup or something like that.

Where are you using a #testsearch.recordcount#???
Don't see it anywhere.

 

by: rudodooPosted on 2006-03-27 at 07:41:09ID: 16301109

farther on down the page. On line 332

It looks like this

<cfoutput><strong><font color="##D68C3A">#testsearch.RecordCount# Listings Matched Your Search Criteria</font></strong></cfoutput></td>

 

by: rudodooPosted on 2006-03-27 at 08:01:28ID: 16301298

Heck it looks like you might have figured something out, I have been getting unable to connect these past few days

 

by: rudodooPosted on 2006-03-27 at 08:16:00ID: 16301481

Instead of cf dump=#Error# I put cf dump=#variables# that looked like it did something I received a different error that goes back to element undefined in #Testsearch.RecordCount#

 

by: SidFishesPosted on 2006-03-27 at 08:24:40ID: 16301565

"How would I create an ODBC connection to an Access database using coldfusion?
what if the database is on a remote server"

You won't likely be able to do this your self unless your host provides a control panel of some sort.. Most hosts require you submit a request to create a datasource as you won't be allowed access to CFAdmin.

Email tech support and ask them to set up the DSN for you.

 

by: rudodooPosted on 2006-03-27 at 08:39:56ID: 16301755

I have a control panel where I can select an option called directory management.

Here I can create a custom directory where I can select between 6 different types of user permissions

1.   Read Permission: This enables anonymous users to view the contents of a directory.

2.  Web Permission: This enables anonymous users to view files in a directory through a Web browser using HTTP.

3.  Browse Permission: This enables anonymous users to view all files in the directory (in directory listing format) by pointing their Web browser to the directory path. You must enable “Read” and “Web” permissions for "Browse" permission to work properly.

4.  Write Permissions: This enables anonymous users to modify the contents of a directory.

5.  Set Root: This enables you to set the directory/subdirectory folder as an application root in the Web server within your site. An application root is the root directory for an application. All directories and files contained within the application root are considered part of the application.

6.  Reset: Click this to reset the permissions for this directory to their default values.

I also have to type the directory name that I want to customize

which is what I am confused about.

Should I type in the directory where I have to store my access database

or

the root folder where my web-pages are stored

 

by: SidFishesPosted on 2006-03-27 at 08:56:39ID: 16301961

these are server settings (ie: folder access control) and not odbc settings. Just because the file is "accessible" doesn't mena that cf can make a connection to it. That has to be done via cfadmin.

I expect you'll need to contact your host and get them to set up an odbc for you.

 

by: SidFishesPosted on 2006-03-27 at 08:57:18ID: 16301971

err... set up a DSN for you

 

by: rudodooPosted on 2006-03-27 at 13:51:17ID: 16305405

I have a dsn set up already.  I just would like to know how to configure the cf query to where I can submit the search form and have it display results from the dsn.

I already put the database in the correct folder

 

by: SidFishesPosted on 2006-03-27 at 14:08:04ID: 16305648


Then if you have set up your dsn correctly in application.cfm then there should be no problem


Looking at this from a different view...This tells me you've a problem with your query not with your dsn      


Element RECORDCOUNT is undefined in TESTSEARCH.


try this first...

<cfquery name="testsearch"  datasource="#Request.DSN#" username="userid" password="passcode">
SELECT * from mls
</cfquery>

<cfoutput>
#Testsearch.recordcount#
</cfoutput>

if that works we can move on to find out what's up with the query

 

by: rudodooPosted on 2006-03-27 at 16:01:22ID: 16306510

Unfortunatly it didn't work.  I still received the same error

 

by: dgrafxPosted on 2006-03-27 at 16:43:56ID: 16306729

rudodoo
It looks like you do Not have your database / datasource setup correctly.
This is an access db - is that correct?
Verify where it is at (the folder location on your host)
Go into your "admin section" on your host where you setup your datasources.
Try deleting the existing datasource (not database) and recreate it again.
When you are selecting database for your datasource - browse to it instead of typing it in (if you can) - this will eliminate misspellings.
You realize the slightest of misspellings will be the same as if you had an entirely different datasource name.
Also, double check the value you have on your site for Request.DSN - make sure it is not misspelled.
Also, do the query without the username & password in your cfquery tag:
<cfquery name="testsearch"  datasource="#Request.DSN#">

If this has been covered in previous posts - I apologize.

 

by: rudodooPosted on 2006-03-27 at 19:23:08ID: 16307378

Yes it is a access db file

I can't browse to the datasource like you suggested but I have double checked to make sure of its locations and they are correct


 I also create just one line in the application.cfm page <cfset request.dsn="MyDataSource">

I also created a .mdw file that I uploaded into the same folder as the access database

I recreated the datasource and have double checked the values and still it is unable to define a recordcount in testsearch

What about the cf dump="variables"

Could I delete that from my above code? I also deleted the username and password.  However I created one in the access database


 

by: dgrafxPosted on 2006-03-27 at 19:28:38ID: 16307414

Remove the username / password from the access database
What is an .mdw file?

Use Exactly this:
<cfquery dataSource="#Request.DSN#" name="Test">
SELECT *
FROM YourTable
</cfquery>
Hello
<cfabort>

Do you get an error?

 

by: SidFishesPosted on 2006-03-27 at 19:45:40ID: 16307495

an mdw file is irellevant in a CF setting...it's ONLY used by access when using access as a front end....


" I also create just one line in the application.cfm page <cfset request.dsn="MyDataSource">"

if you actually used "MyDataSource" as the name it will fail...you need to set the dsn to the dsn that was set up by your host

cfdump has no effect on anything... it simply outputs then variables referenced///it is a debugging tool and nothing more...you can delete all references and it will make no difference to your code.

 

by: rudodooPosted on 2006-03-27 at 19:46:51ID: 16307503

a .mdw file is the workgroup information file that I was told was missing from the remote server.  Which previously stopped me from connecting to the access database or so I was informed

No I didn't get an error!!!!  How can I configure that solution with the original script that I created?

Just to refresh your memory

<!--- Get mls list from database --->
<cfif isDefined("FORM.submit")>
<cftry>
<cfquery name="testsearch"  datasource="#Request.DSN#" >
SELECT mls.mlsid, mls.city, mls.state, mls.zip, mls.area, mls.price, mls.listing,
(SELECT TOP 1 mlspicpath FROM TblPicPaths WHERE mlsid = mls.mlsid) AS mlspicpath
FROM MLS
Where 0=0
<!---Search by mlsid or text fields--->
<cfif Form.mlsid IS NOT "">
AND mls.mlsid LIKE '%#FORM.mlsid#%'
</cfif>
<!---Search by CITY or list fields--->
<cfif Form.city is not "">
and mls.city = '#Form.city#'
</cfif>
<!--- search by state --->
<cfif Form.state is not "">
and mls.state = '#Form.state#'
</cfif>
<!--- Select zip --->
<cfif Form.zip is not "">
and mls.zip like '%#form.zip#%'
</cfif>
<!--- select area --->
<cfif Form.area is not "">
and mls.area ='#form.area#'
</cfif>
<!--- select price--->
<!--- select min price--->
<cfif Form.min_price is not "">
and mls.price >=#form.min_price#
</cfif>
<!--- select max price--->
<cfif Form.max_price is not "">
and mls.price <=#form.max_price#
</cfif>
<!---select listing--->
<cfif form.listing is not "">
and mls.listing ='#form.listing#'
</cfif>
</cfquery>

 

by: dgrafxPosted on 2006-03-27 at 20:35:24ID: 16307672

"No I didn't get an error!!!!  How can I configure that solution with the original script that I created?"

Are you saying it's working now?
Or what do you mean by No I didn't get an error?

If you're still getting errors - it's pointless to configure original script.

If not getting errors then try the query you have. It looks ok on the surface ???

 

by: rudodooPosted on 2006-03-27 at 20:59:10ID: 16307770

No I wasn't getting any errors  I received a blank page that read hello

 

by: dgrafxPosted on 2006-03-28 at 03:46:43ID: 16309535

Well you should be cooking with heat now with no errors.

Use Exactly this:
<cfquery dataSource="#Request.DSN#" name="Test">
SELECT *
FROM YourTable
</cfquery>
<cfdump var="#test#">
<cfabort>

Do you get an error or does it dump the query?


 

by: rudodooPosted on 2006-03-28 at 11:46:54ID: 16314084

yes it shows all the info from the database

 

by: rudodooPosted on 2006-03-28 at 12:22:04ID: 16314489

so i guess it dumps the query

 

by: dgrafxPosted on 2006-03-28 at 13:01:13ID: 16314870

ok - so now Use Exactly this:

<cfquery name="testsearch"  datasource="#Request.DSN#" >
SELECT mls.mlsid, mls.city, mls.state, mls.zip, mls.area, mls.price, mls.listing,
(SELECT TOP 1 mlspicpath FROM TblPicPaths WHERE mlsid = mls.mlsid) AS mlspicpath
FROM MLS
Where 0=0
</cfquery>
Hello Again
<cfabort>

Will it show "Hello Again" without an error?

 

by: rudodooPosted on 2006-03-28 at 17:41:10ID: 16317170

I got it working I appreciate it you get the points

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...