Solved

How to use the path (database file)  of a datasource in a SQL query.

Posted on 2001-06-05
9
182 Views
Last Modified: 2013-12-24
I have query like this
<CFQUERY NAME="SAV1" DATASOURCE="usertables" dbtype="ODBC">
INSERT INTO USER(WEBPAGEID,COUNTRYID)
IN 'D:INETPUB\WWWROOT\DATABASES\CAWS1.MDB'
SELECT WEBPAGEID,COUNTRYID
FROM USERCONFIG_S
WHERE .....
</CFQUERY>
User is a table in a different database CAWS1.MDB and I use the query to insert the records in it hardcoding its path as shown above.
As CAWS1.MDB is a datasource ,I was wondering if its path as given in Database file field of the Administrator section can somehow be used so that I donot have to hardcode the path.
Is there any other way.
Thanks
AA
0
Comment
Question by:Ahson
  • 5
  • 4
9 Comments
 
LVL 5

Expert Comment

by:Yog
ID: 6155886
hi aa, creating a dsn without odbc is like this

<cfset DBPath="D:INETPUB\WWWROOT\DATABASES\CAWS1.MDB">
<cfquery name="QueryName"
 datasource="#DBPath#"
 dbtype="OLEDB"
 provider="yourprovider"
 providerdsn="#DBPath#"
 username="Admin"
 password="">

but what u r doing i think is not possible, meaning in one cfquery , trying to so a select and insert into another different database..board is quick - so u can wait to see answers..

cheers.
yog
0
 

Author Comment

by:Ahson
ID: 6156403
As we know every datasource is associated with a database file which is the path for the file.Is it possible to save the path for a datasource in a variable.i.e CAWS is a datasource and has a path associated to it .can we store the path for the CAWS datasource using some colf fusion function etc.
Thanks
0
 
LVL 5

Expert Comment

by:Yog
ID: 6156490
awson, didn't get you - u mean find in your file directory - where this file CAWS1.MDB exists and find the path - yea possible
0
 

Author Comment

by:Ahson
ID: 6156840
yes you are right Yog.
how can we do that.
many thanks
AA
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 5

Expert Comment

by:Yog
ID: 6158034
Ahson sorry
simply use the
fileexists() to check if the file is available and directoryexists() to see if the directory is available..

cheers.
yog ..
0
 

Author Comment

by:Ahson
ID: 6158894
Thanks But I think I confused you.
suppose we have a datasource = "Caws".Can we store the path to this datasource in a variable that could be used in a query.
Thanks again
AA
like
<cfset my_path=some function getting the path for datasource CAWS1.mdb>

<CFQUERY NAME="SAV1" DATASOURCE="usertables" dbtype="ODBC">
INSERT INTO USER(WEBPAGEID,COUNTRYID)
IN '#my_path#'
(instead of
IN D:INETPUB\WWWROOT\DATABASES\CAWS1.MDB')

SELECT WEBPAGEID,COUNTRYID
FROM USERCONFIG_S
WHERE .....
</CFQUERY>
Thanks
AA
0
 
LVL 5

Accepted Solution

by:
Yog earned 50 total points
ID: 6159956
Ah, no you cant do that , better do

<cfquery name="lastquery" dsn="olddsn">
SELECT WEBPAGEID,COUNTRYID
FROM USERCONFIG_S
WHERE .....
</cfquery>

then
<cfoutput query="lastquery">

<cfquery dsn"newdsn" query="newquery">
INSERT INTO USER(WEBPAGEID,COUNTRYID)
VALUES(#lastquery.webpageid#,#lastquery.countryid#)
</cfquery>

</cfoutput>
0
 

Author Comment

by:Ahson
ID: 6160377
Thanks Yog
That was very helpful.I appreciate.
AA
0
 

Author Comment

by:Ahson
ID: 6160379
Thanks Yog
That was very helpful.I appreciate.
AA
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

A web service (http://en.wikipedia.org/wiki/Web_service) is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now