CodeCharge Studio
search Register Login  

Visual Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> Archive -> GotoCode Archive

 Switching database on the fly on entering a page

Print topic Send  topic

Author Message
John Ramsden
Posted: 12/06/2002, 9:15 AM


I have a page with links to another page that expects a query string
e.g. "msgreset.php?cust=dbsmith" where the 'cust' argument is the name
of a database specific to a customer. (The databases for all customers
have the same structure; so the page works trhe same with any.)

In the page msgreset.php I am fetching and parsing the query string
OK; but there doesn't seem to be a non-hack way to switch connections
from the database with which I set up the grid on that page.

I started by adding an AfterInitialization event procedure; but that
didn't work. I then tried hacking the database initialization method
(which I was particularly keen to avoid having to do), to plug into
the initialization method the connection details for the new database;
but that also made no difference and the page obstinately continues
to stick with the original hard-coded database. (I specified this as
a persistent connection, which could have something to do with my
problems.)

For a product that prides itself on its database features it seems
amazing that one can't switch databases on the fly, as described
above. Can anyone offer any suggestions? TIA

Cheers

John Ramsden (john_ramsden@sagitta-ps.com)
Tom
Posted: 12/12/2002, 11:21 AM

Not sure if this is what you are trying to do but my code takes a url parameter to switch databases. Basically, I customized the common file to change the connect string based on the existence of a url parameter. I then store that url parameter in a session parameter for all pages to use. I test for a url parameter first, then for a session parameter. I code in ColdFusion but you should be able to noodle thru the example.
In common.cfm:
************* as found in common.cfm
<!---Connections @-47E205FE--->
<CFSET Request.DefConnection="myConnection">
<CFSET Request.db_cnAutotest_USER_NAME="myname">
<CFSET Request.db_cnAutotest_USER_PASSWORD="mypwd">
<CFSET Request.db_cnAutotest_DB_TYPE="ODBC">
<CFSET Request.db_cnAutotest_DS="myodbc">
<!---End Connections --->
********************* MY CUSTOM STUFF ***************************
<CFPARAM NAME="url.sid" DEFAULT="">
<CFPARAM NAME="Session.Instance" DEFAULT="">
<!--- First check to see if someone has passed a url parameter
and if they did use it, otherwise see if the session instance
is set and use it
Do not change this order as this makes logical sense in order
to override and reset the session variable
--->
<!--- check url query string value first in case we need to change --->
<CFIF ucase(url.sid) EQ "DB1">
<CFSET Request.db_cnAutotest_DS="odbcDb1">
<CFSET Request.db_cnAutotest_USER_PASSWORD="pwddb1">
<CFELSEIF ucase(url.sid) EQ "DB2">
<CFSET Request.db_cnAutotest_DS="odbcdb2">
<CFSET Request.db_cnAutotest_USER_PASSWORD="pwddb2">
<!--- now check session parameter --->
<CFELSEIF ucase(Session.Instance) EQ "DB1">
<CFSET Request.db_cnAutotest_DS="odbcdb1">
<CFSET Request.db_cnAutotest_USER_PASSWORD="pwddb2">
<CFELSEIF ucase(Session.Instance) EQ "DB2">
<CFSET Request.db_cnAutotest_DS="odbcdb2">
<CFSET Request.db_cnAutotest_USER_PASSWORD="pwddb2">
<CFELSE>
<CFSET Request.db_cnAutotest_DS="odbcdb1">
<CFSET Request.db_cnAutotest_USER_PASSWORD="pwddb1">
</CFIF>
<!--- Dlookup requires a where clause so I stuck in a simple one
This is used to place what database we are connected to in the title
so I know where I am when working with the application.
I make a query to the database to ensure that I'm in the right instance
and don't have false indication based on a variable. This does cause
a performance hit of anywhere from 10 to 100 ms on each page but I think
that it is worth it.
--->

<CFMODULE Template="CCDLOOKUP.cfm" Table="GLOBAL_NAME" FIELD="GLOBAL_NAME" WHERE="1=1">
<CFSET Session.Instance = ucase(listfirst(ccdlookup,"."))>

   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

MS Access to Web

Convert MS Access to Web.
Join thousands of Web developers who build Web applications with minimal coding.

CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.