DB Connections: Parent Path vs. Hard coded

Dave

Perch
What is the disadvantage in using hard-coded paths in a MS Access connection string when using a DSN-less connection?

I've noticed that in the effort to move my website to JodoHost that using the parent path option is causing a lot of re-work in my pages. I'm using, whenever possible, include files to set up the connections, but when trying to use parent paths I can't just simply change my includes as the parent path is dependent on the directory structure.

i.e. my included parent path connection strings work when the pages are in the root directory, but need to be different if the pages are in sub-directories, and different again if the pages are in sub-directories of sub-directories.

If I was to use hard-code connections, I could just simply change my includes and all the pages would work. I previously used a virtual path, which was always the same regardless of where the page was. I'm not sure why virtual paths (as opposed to parent and hard-coded) don't work on JodoHost.

Is my site subject to being moved to a different server for load rebalancing reasons, which could cause the hard-coded paths to break?

Thanks.
 
You are welcome to use hard-coded paths as well here at JodoHost and that wouldn't be a problem. Parent paths is what most people use because once coded that way, you can move your code from host to host without making any changes at all.
 
Thanks for the speedy response, Yash. I guess I should have asked this question when I was first told that it was recommended to use parent paths. When I first moved my site over in my trial account I simply changed my paths to hard-coded to get it working. Since I moved to a paid account I've been going crazy customizing my pages to work with parent paths for the last day and half, and all for nothing. At least I can go back and not have the headache of parent paths from this point on.

I'm very impressed with the speed of responses here at JodoHost.
 
Re: Re: DB Connections: Parent Path vs. Hard coded

Well, I actually prefer to use virtual/parent paths in my code. But to make parent paths work at Jodohost, you have to ask support to enable them, that's all. And yes, I usually make a page calles "inc_utils.asp" and include it anywhere I need database connection. In this page go all "garbage" - global functions, to be used in several pages. So no matter if I'll use physical or virtual paths, I will change the code only in one place.
 
I prefer using virtual paths as well, except they don't seem to work here. Parent paths and Virtual paths are two different things. Using Parent paths, you have to use "../database/myDB.mdb" or "../../database/myDB.mdb" depending on what directory level the pages are at. You don't need that for a real virtual path, which I would be able to simply use a single connection string regardless of the page location.

I did ask JodoHost to enable Parent Paths, which is where I ran into problems. My include file then only worked at one directory level. I don't keep all my files in the root directory. That would be a nightmare to manage. I've changed my include file and am changing all my previous individual page changes back to point to the include. Everything will run much smoother now.

I'll be happy when I'm done fiddling with the changes required to get things running smoothly here, so I can move my domain name from my original host and get back to doing useful updates to the site.
 
I don't keep all my files in the root directory
Sure, I don't do this either. But never ran into any problem with virtual or parent paths (which are just same, just parent path means you can step up in directory structure, while virtual - the top most folder is your wwwroot folder). Works always perfectly, dunno why you had any troubles with them. ?(
 
I'm not sure why I had problems either. Maybe it's because I created a database directory to hold the databases? This is outside my site directory. If I didn't use the elipses, either ../ or ../../ depending on the location, to to indicate where to find the DB, then it always looked inside my site directory for the database folder. Do you have your databases inside or outside your site directory?
 
Ah, yes, I see why you have problem. And I do create a folder above wwwroot too (otherwise anyone will be able to download the database). But in pure ASP I have used either physical path (just like you) or - more often - DSN, which saves a lot of pain of DSN-less connections.
In ASP.NET though, you can use a parent/virtual path in this form: "/../db/mydb.mdb". See, I start from the root folder (first "/") and up one level (".."), etc. This didn't work in ASP 3.0 as if I remember right
 
This should work in ASP 3.0

Server.MapPath("../db/mydatabase.mdb")

Don't know how exactly your connection string looks
 
Back
Top