PDA

View Full Version : Using Server.MapPath in a connection string


paulgt
07-07-2009, 08:29 PM
Hi everyone.
I wonder if someone can help me.

I have designed an ASP web site using DW CS4 and I have a problem using Server.MapPath in the database connection string. The database is Access 2003.

If i use a direct path in the connection string e.g.

<%
// FileName="Connection_ado_conn_string.htm"
// Type="ADO"
// DesigntimeType="ADO"
// HTTP="true"
// Catalog=""
// Schema=""
var MM_DatabaseSVBB_STRING = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=c:/inetpub/wwwroot/database/svbb.mdb"
%>
Everything works fine... but this is obviously no good on a web server, so I am trying to use a Server.MapPath command as below:


<%
// FileName="Connection_ado_conn_string.htm"
// Type="ADO"
// DesigntimeType="ADO"
// HTTP="true"
// Catalog=""
// Schema=""
var MM_DatabaseSVBB_STRING = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ="& Server.MapPath("/database/svbb.mdb")
%>
However, this version always causes the error

ADODB.Command error '800a0bb9'
Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.
/index.asp, line 6
The bit of the web page that crashes is as below:
<%@LANGUAGE="JAVASCRIPT" CODEPAGE="65001"%>
<%Session.LCID = 2057%>
<!-- #include file="Connections/DatabaseSVBB.asp" -->
<%
var rsQueryAll10Days_cmd = Server.CreateObject ("ADODB.Command");
rsQueryAll10Days_cmd.ActiveConnection = MM_DatabaseSVBB_STRING;
rsQueryAll10Days_cmd.CommandText = "SELECT * FROM QueryAll10days ORDER BY [Date], [Time] ASC";
rsQueryAll10Days_cmd.Prepared = true;

var rsQueryAll10Days = rsQueryAll10Days_cmd.Execute();
var rsQueryAll10Days_numRows = 0;
%>
I do hope someone is able to advise me on this..
Thanks in anticipation
PaulGT

mangofreak
08-17-2009, 05:19 PM
Did you know that MapPath only works when the DB is on the same directory as the files you are working on? Also, password you database. I had nightmares with Access files being hacked by Pakistany hackers and some Other hooligans from Turkey. Also, validate forms and the whole works.

paulgt
08-17-2009, 07:16 PM
Hi
thanks for your response. I was beginning to wonder if anyone would.
Your information is very useful. I will re-think my strategy.
Paulgt

mangofreak
08-17-2009, 07:28 PM
No problem. I have been absent from the forum for months now, but I'll be checking it more often. Let me know how it goes.

Cheers,

Javier