PDA

View Full Version : Custom connection string?


mattboy_slim
03-17-2003, 08:13 PM
I do not understand custom connection strings at all, but what I have a need for, is to point to a database that is down one level rather than in the default directory as is shown:

<%
Dim strConnect
strConnect = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ="& Server.MapPath("data.mdb") &";DefaultDir="& Server.MapPath(".") &";DriverId=25;FIL=MS Access;MaxBufferSize=512;PageTimeout=5"
%>


The database is located within the directory: _Admin

Again guys, your help is much appreciated.

Thanks,

raf
03-17-2003, 08:30 PM
Well, for starters, always put your connectionstring in an include.
Second: never post the db's name or adress here !! (If i go to your side and type in the db-adress, IE willdownload it.

Here's one of my connectionstrings


dim conConnection,
set conConnection=server.CreateObject("adodb.connection")
conGranIT.Open("provider=microsoft.jet.oledb.4.0;data source="&server.MapPath("db/thedb.mdb"))

(it looks so short and silly, but then, i nly use access for almost-single-user db's that don't need a lot of power and seecurity (which i take care of in my app)

mattboy_slim
03-17-2003, 08:49 PM
Well anybody could snag this database if they really wanted it. There is nothing there that's not test junk. But nevertheless, good information for the future. This is simply for a test to help me out learning.

Oh yeah, and the connection code is in an include file.

mattboy_slim
03-17-2003, 09:23 PM
Here's the problem exactly:
======================

Error Message:

Microsoft OLE DB Provider for ODBC Drivers error '80004005'

[Microsoft][ODBC Microsoft Access Driver] Could not find file '(unknown)'.

/dickinson/admin/links.asp, line 24

======================
Line 24 of links.asp states:
======================
objConn.Open strConnect
---------------------------------------
Connection String:

<%
Dim strConnect
strConnect = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ="& Server.MapPath("admin/data.mdb") &";DefaultDir="& Server.MapPath(".") &";DriverId=25;FIL=MS Access;MaxBufferSize=512;PageTimeout=5"
%>


========================
If I change Server.MapPath to simply "data.mdb", and copy the database to the default directory, then the page loads fine. If the database is only under the "admin" directory, then it doesn't work.

??

mattboy_slim
03-17-2003, 09:51 PM
Now I'm getting this error message.
====================================

Microsoft VBScript compilation error '800a03f2'

Expected identifier

/dickinson/admin/connection.inc, line 2

Dim strConnect,
---------------^

======================================

EDIT: Fixed. Back the previous problem.

mattboy_slim
03-17-2003, 10:13 PM
Nevermind, problem solved....

...
...
...

for now...

whammy
03-18-2003, 01:21 AM
raf, you have the wrong idea... it IS possible to keep people from downloading your access db:

You need to store the access database ABOVE the root of your web directory, so it cannot be downloaded...

Then you can use Server.MapPath() to map the LOCAL path of the file on the server's hard drive, in order to access the Access database from your web application.

Here's a handy one that always works for me (might take a little tweaking depending upon your setup):

sConnString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & _
Mid(Server.MapPath("\"), 1, InStrRev(Server.MapPath("\"),"\")-1) & "\.mdb;" & _
"Persist Security Info=False;"

Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open sConnString

I actually got that by slightly shortening the code that a suggested brinkster.com connection string uses, that always works for me... and since the database directory is in the "same space" as the webroot, it's impossible for someone to download your access database, since they don't have access to it from the web - it's stored ABOVE the root as far as the website is concerned... get it? That's what Server.MapPath() is for, at least in part. ;)

raf
03-18-2003, 07:27 PM
whammy, good to know:thumbsup: ,
but; i'm not running my own server and most free servers just give you one "write" folder (mostly something hard-to-guess as "db") in the virtual root .

So i wouldn't know how to store it above the root.