Solved

Database Server.Mappath error

Posted on 2003-10-26
12
522 Views
Last Modified: 2013-12-03
HELP !!!
The problem i have is my database works O.K when stored with-in the same folder as my .asp, However i want to store my database.mdb in a separate folder in the root directory. i have tried different mappings and get errors.

Old location Containg .asp Page ( C:\Inetpub\wwwroot\intranet\PublicSite ) Database works if stored here !!!!
New Database Location ( C:\Inetpub\wwwroot\intranet\databases\ASP_GuestBook )

I am using Windows XP Pro & IIS 5.1
Coding in Dreamweaver MX

Please Help, driving me crazy
__________________________________________________________________________________________________
Here is a copy of my Original Code
__________________________________________________________________________________________________

<%  response.buffer=true  %>
<%  
'declaring all database variables and opening connections  

Set dc = Server.CreateObject("ADODB.Connection")  
Set rs = Server.CreateObject("ADODB.Recordset")  

 dc.Open "DBQ=" & Server.Mappath("database.mdb") & ";Driver={Microsoft Access Driver (*.mdb)};"  

%>
<%  
' this script adds a record to database  

openMethod = request.form ("openMethod")  
if openMethod = "postMessage" then  'this line checks if the ASP file should post a message

USER_DATE = FormatDateTime(Date, 1)   'records the post date and time
USER_NAME = request.Form ("USER_NAME")  
user_club = request.Form ("user_club")  
USER_MAIL = request.Form ("USER_MAIL")  
 
USER_MESSAGE = request.Form ("USER_MESSAGE")  

if (USER_NAME = "")then
      response.write ("<font size=+2> <strong><em>Please Enter Your Name</em></strong></font><br>") & VBCRLF  
elseif (user_club = "")then
      response.write ("<font size=+2><strong><em>Please Enter Name of the Recipient</em></strong></font><br>") & VBCRLF  
elseif (USER_MESSAGE = "") then'this code dysplays an error message if user doesn't fill in the "*" marked fields: name, e-mail and Message
      response.write ("<font size=+2><em><strong>Please Enter Your Comment or Question</strong></em></font><br>") & VBCRLF  
End IF





if len(USER_MESSAGE) > 4096 then USER_MESSAGE = Left(USER_MESSAGE, 4096)  End If 'this sets the message size limit to 4 kb: if it's more then 4kb, a part of it will be erased  
 
MYSQL = "SELECT GBOOK.* FROM GBOOK"  'selects the guestbook table in the database  

if NOT (USER_NAME = "" or USER_MESSAGE = "" or user_club = "") then  'if all fields are valid, adds a record to the DB
 
   
rs.Open MYSQL, dc, 1, 3    'opens the database

rs.AddNew  
rs.Fields("USER_DATE") = USER_DATE  
rs.Fields("USER_NAME") = USER_NAME  
rs.Fields("user_club") = user_club  
rs.Fields("USER_MAIL") = USER_MAIL  

rs.Fields("USER_MESSAGE") = USER_MESSAGE  
rs.Update  



response.redirect ("guestbook.asp") 'redirects to the guestbook page

End If

End If
%>
<body bgcolor="#FFFFFF" text="#000000" link="#00FF00" vlink="#00FF00" alink="#00FF00">
<style type="text/css">
<!--
*    
BODY {


   scrollbar-face-color:        #FFFFFF;
 scrollbar-shadow-color:     #000000;
   scrollbar-3Dlight-color:   #000000;
  scrollbar-arrow-color:     #000000;
   scrollbar-track-color:      #FFFFFF;
  scrollbar-darkshadow-color: #000000;

   }

//-->
</style>
<form action="guestbook.asp" method="post">
  <div align="center">
    <p>
      <input type=hidden name=openMethod value=postMessage>
      <strong><font color="#000000" size="4">Please fill in all the items shown
      with</font></strong> <font color="#000000" size="4"><strong>*</strong> <strong>next
      to them</strong></font> <br>
      <font color="#000000">Highlight <em><strong>Not Defined</strong></em> to
      enter your Email address</font></p>
  </div>
  <table border=1 align=center cellpadding=2 cellspacing=2 bordercolor="#000000">
    <tr>
      <td bordercolor="#9999CC" bgcolor="#9999CC">
        <div align="center"><em><strong><font color="#000000">Name</font><font color="000000"><font color="#FFFFFF">*</font><font color="#000000">:</font></font></strong></em></div></td>
      <td align=right bordercolor="#000000">
        <div align="center">
          <input size=35 type=text name=USER_NAME value="" >
        </div></td>
    </tr>
    <tr>
      <td bordercolor="#9999CC" bgcolor="#9999CC">
        <div align="center"><em><strong><font color="#000000"> &nbsp;E-Mail:</font><font color="000000"><font color="#FFFFFF">(Optional)
          </font></font></strong></em></div></td>
      <td align=right bordercolor="#000000">
        <div align="center">
          <input size=35 type=text name=USER_MAIL value="Not Defined">
        </div></td>
    </tr>
    <tr>
      <td bordercolor="#9999CC" bgcolor="#9999CC">
        <div align="center"><em><strong><font color="#000000">Attention</font><font color="000000"><font color="#FFFFFF">*</font><font color="#000000">:</font></font></strong></em></div></td>
      <td align=right bordercolor="#000000">
        <div align="center">
          <input size=35 type=text name=user_club value="">
        </div></td>
    </tr>
    <tr>
      <td valign=top bordercolor="#9999CC" bgcolor="#9999CC">
        <div align="center"><em><strong><font color="#000000">Message</font><font color="000000"><font color="#FFFFFF">*</font><font color="#000000">:</font></font></strong></em></div></td>
      <td align=right bordercolor="#000000">
        <div align="center">
          <textarea name=USER_MESSAGE cols=28 rows=4 wrap="PHYSICAL"></textarea>
        </div></td>
    </tr>
    <tr>
      <td bordercolor="#9999CC" bgcolor="#9999CC"></div>&nbsp;</td>
      <td height=50 align=right valign=top bordercolor="#9999CC" bgcolor="#9999CC">
        <div align="center">
          <input name="post" type=submit id="post"  value="Post It">
          &nbsp;
          <input type=reset value="Clear">
        </div></td>
    </tr>
  </table>
  <font color="#FFFFFF"></font>
</form>
<%  
MYSQL = "SELECT ID, USER_DATE, USER_NAME, user_club, USER_MAIL,  USER_MESSAGE FROM GBOOK ORDER by ID DESC"  

rs.Open MySQL, dc, 3, 1
%>
<%    
'this is the records counter and navigation stuff

currentPage = request.queryString ("id")  'check what page to dysplay (this is used for nav)
If currentPage = "" then  
      currentPage = "1"  
End If  

pageSize = 10   'pageSize is the ammout of records per page to be dysplayed

Records = rs.RecordCount                   'this is the total ammount of records in the DB

if NOT (Records = 0) then                     'if there are no records in the DB, server may report an error.  I used the IF structure to prevent this error.  
      rs.pageSize = pageSize
      rs.AbsolutePage = currentPage               'absolutePage is the page to be dysplayed - don't change it: it depeds on the user's choice  
End If

pageNext = currentPage + 1
pagePrev = currentPage - 1
Pages = Records \ pageSize  
if Records mod pageSize then
Pages = Pages + 1
End If

%>
<table width=100% border=0 cellspacing=0 cellpadding=0>
  <tr>
    <td width=50% align=left valign=top bgcolor="#9999CC"><font color="#FFFFFF"><strong><em><font color="#FFFFFF">Pages:</font></em></strong>&nbsp;
      <font color="#FFFFFF">
      <% if NOT pagePrev < 1 then %>
      </font><a href=guestbook.asp?id=<% = pagePrev %>>Prev</a>
      <% else %>
      <font color="#000000"><strong><em>Prev</em></strong></font></font> <font color="#FFFFFF">
      <% End If %>
      <font color="#FFFFFF"> |</font></font> <font color="#FFFFFF">
      <%  While NOT pageNumber = Pages pageNumber = pageNumber + 1  %>
      </font><font color="#FFFFFF">
      <% if CInt (pageNumber) = CInt (currentPage)  then %>
      <% = pageNumber %>
      <font color="#FFFFFF"> |</font></font> <font color="#FFFFFF">&nbsp; </font><font color="#FFFFFF">
      <% else %>
      <a href=guestbook.asp?id=<% = pageNumber %>>
      <% = pageNumber %>
      </a> <font color="#FFFFFF">|</font></font> <font color="#FFFFFF">
      <% End If %>
      <% Wend %>
      <% if NOT pages < pageNext then %>
      <a href=guestbook.asp?id=<% = pageNext %>>Next</a>
      <% else %>
      <strong><font color="#000000"><em>Next</em></font></strong></font> <font color="#FFFFFF">
      <% End If %>
      </font></td>
    <td width=50% align=right valign=top bgcolor="#9999CC"><font color="#000000"><strong>Total
      entries:</strong></font>&nbsp; <% = Records %></td>
  </tr>
</table>
<%  
if NOT (CInt(Records) = 0) then  'if there are no records in the database it doesn't go on dysplaying then and only sais that there are no records  

Do While (Not rs.EOF) and (currentRecords < pageSize)  'runs through the records and dysplays them
currentRecords = currentRecords + 1  'counts currently displayed records
%>
<hr noshade>
<table width=100% border=0 cellspacing=0 cellpadding=0>
  <tr>
    <td valign=top align=left width=50%><p><font color="#9999CC"><strong><em>Name:</em></strong></font>&nbsp;<%= rs("USER_NAME") %><br>
        <font color="000000"><em><font color="#000000"><strong><font color="#9999CC">E-mail:</font></strong></font></em>&nbsp;</font><%= rs("USER_MAIL")%> <br>
        <font color="000000"><em><font color="#000000"><strong><font color="#9999CC">Attention:</font></strong></font></em>&nbsp;</font><%= rs("user_club") %><br>
    <td valign=top align=right width=50%><font color="#000000"><strong><font color="#9999CC">Posted:</font></strong></font><font color="#9999CC">&nbsp;</font><%= rs("USER_DATE") %></td>
  </tr>
</table>
<P align=justify><strong><font color="#000000"><em><font color="#9999CC">Message:</font></em></font><font color="#9999CC">&nbsp;</font></strong><%= rs("USER_MESSAGE") %>
  <%  
      rs.MoveNext  
      Loop  
else  
      response.write ("<P align=center><font size=+1>No records found, be the first to post a comment!</font></center><br>") & VBCRLF  
End If
%>
  <font color="#FFFFCC"></font>
  <%  
'closing connections and resetting all database variables  

rs.Close
Set rs = Nothing
dc.Close
Set dc = Nothing
%>
0
Comment
Question by:Daffyy33
12 Comments
 
LVL 29

Expert Comment

by:David H.H.Lee
ID: 9622263
Daffyy33,
You should use this solutions :
>>
Old location Containg .asp Page ( C:\Inetpub\wwwroot\intranet\PublicSite ) Database works if stored here !!!!
New Database Location ( C:\Inetpub\wwwroot\intranet\databases\ASP_GuestBook )

-Solution :
dc.Open "DBQ=" & Server.Mappath("..\databases\ASP_GuestBook\database.mdb") & ";Driver={Microsoft Access Driver (*.mdb)};"  

Regards
x_com
0
 

Author Comment

by:Daffyy33
ID: 9622273
x_com Thank-you for you response,

I tried your suggestion , but i am still getting a errors
______________________________________________
See the following
______________________________________________
The page cannot be displayed
There is a problem with the page you are trying to reach and it cannot be displayed.

--------------------------------------------------------------------------------

Please try the following:

Click the Refresh button, or try again later.

Open the localhost home page, and then look for links to the information you want.
HTTP 500.100 - Internal Server Error - ASP error
Internet Information Services

--------------------------------------------------------------------------------

Technical Information (for support personnel)

Error Type:
Microsoft OLE DB Provider for ODBC Drivers (0x80004005)
[Microsoft][ODBC Microsoft Access Driver]General error Unable to open registry key 'Temporary (volatile) Jet DSN for process 0xaf4 Thread 0x444 DBC 0x14e0ff4 Jet'.
/intranet/PublicSite/guestbook.asp, line 9


Browser Type:
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)

Page:
GET /intranet/PublicSite/guestbook.asp

Time:
Sunday, October 26, 2003, 11:38:42 PM


More information:
Microsoft Support
 
0
 
LVL 29

Expert Comment

by:David H.H.Lee
ID: 9622296
Daffyy33 ,
If your main directory is "intranet",
you just need to use
dc.Open "DBQ=" & Server.Mappath("databases\ASP_GuestBook\database.mdb") & ";Driver={Microsoft Access Driver (*.mdb)};"  

-Note "../" is use when you want to get an upper level of your directory.

Regards
x_com
0
 

Expert Comment

by:smacca
ID: 9622302
Define your connection string in your "global.asa" file:

   Application("ConnectionString") = "Provider=Microsoft.Jet.OLEDB.4.0;User ID=;Password=;Data Source=" + Server.MapPath("/db/default.mdb")

Create an include file called "global_inc.asp" and define the following functions:

<%
      '-------------------------------------------------------------------------------
      'Returns an ADO Connection object to the site database
      '-------------------------------------------------------------------------------
      Function GetDBConnection()
            
            Dim objConn            
            Set objConn = Server.CreateObject("ADODB.Connection")            
                        
            If Response.IsClientConnected Then            
                  
                  With objConn
                        .ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;User ID=;Password=;Data Source=" + Server.MapPath("/db/default.mdb")
                        .ConnectionTimeout = 30
                        .Open
                  End With                  
            
            End If
            
            'Return connection
            Set GetDBConnection = objConn
            
            'Release resources
            Set objConn = Nothing

      End Function
%>

Include the file at the top of each page:

<%@ LANGUAGE=VBScript%>
<!-- #include virtual="/includes/global_inc.asp" -->

Now you have imported the global_inc.asp file (make sure you stored it in the location specified above) use the following code to get a connection to database:

<%      
      '-------------------------------------------------------------------------------
      ' Open database connection
      '-------------------------------------------------------------------------------
      Dim objConn
      Set objConn = GetDBConnection()

%>

Be sure to close and dereference at the bottom of each page:

<%
  objConn.Close
  Set objConn = Nothing
%>


I have not found a better way of doing this stuff in ASP.
Hope it all works.
0
 
LVL 29

Expert Comment

by:David H.H.Lee
ID: 9622309
i get it what you need, try this
dc.Open "DBQ=" & Server.Mappath("..\..\databases\ASP_GuestBook\database.mdb") & ";Driver={Microsoft Access Driver (*.mdb)};"  

Regards
x_com
0
 
LVL 29

Expert Comment

by:David H.H.Lee
ID: 9622344
Daffyy33 ,
Let me explain to you the how to access the file in others directory.
Eg:
-let said your main folder is http://www.yoursite.com
-you store all the .asp file in folder ASP -> http://www.yoursite.com/ASP
-you want to get access to MDB file at different folder - MDB -> http://www.yoursite.com/MDB/db.mdb
 When you access the MDB folder, you need to get into up 1 level :>> server.mappath("../MDB/db.mdb")
 if your main folder is http://www.yoursite.com/intranet/ASP,
 you need to get -2 level to get the Mdb file -> server.mappath("../../MDB/db.mdb")

I think my first solutions had done the tricks.
>>
>>
Old location Containg .asp Page ( C:\Inetpub\wwwroot\intranet\PublicSite ) Database works if stored here !!!!
New Database Location ( C:\Inetpub\wwwroot\intranet\databases\ASP_GuestBook )

if your main directory is wwwroot
-server.mappath("../intranet/databases/ASP_GuestBook/database.mdb")

if your main directory is intranet
-server.mappath("../databases/ASP_GuestBook/database.mdb")

Regards
x_com
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:Daffyy33
ID: 9622463
x_com

I appreciate your assistance

I am new a .asp so my head is spinning

I read your comments and tried them out.. i don't understand i keep getting errors

I have succussfully mapped two login screens i used with-in the site using physical addresses
DB.open "Provider=Microsoft.Jet.OLEDB.4.0;Data source=C:\Inetpub\wwwroot\intranet\databases\login\login.mdb"

I tried MAPPING USING THE SAME PROCURE  as above,"But got a error message use a virtual path "
BUT no good as a phyiscal address to my "GUESTBOOK", so i tried a Virtual Path Address
dc.Open "DBQ=" & Server.Mappath("../databases/ASP_GuestBook/database.mdb")  & ";Driver={Microsoft Access Driver (*.mdb)};"

which we have looked at !!!

I tried your changes and still no good

My local address is - http://localhost/intranet/index.htm  

And the code "In guestbook.asp" is:
dc.Open "DBQ=" & Server.Mappath("../databases/ASP_GuestBook/database.mdb")  & ";Driver={Microsoft Access Driver (*.mdb)};"

When i link from my index, to open guestbook.asp thats when the errors occur, could i be overseeing something ??

Regards Daffy (Who is feeling Daffy)
0
 
LVL 29

Accepted Solution

by:
David H.H.Lee earned 125 total points
ID: 9623096
Daffyy33,
Let see this sample, let's begin from easier way :

>>
My local address is - http://localhost/intranet/index.htm  <------All your .asp or html files located

You need to access mdb file at :
- http://localhost/databases/ASP_GuestBook/database.mdb

use this solutions :
dc.Open "DBQ=" & Server.Mappath("../databases/ASP_GuestBook/database.mdb")  & ";Driver={Microsoft Access Driver (*.mdb)};"

-Make sure you have the read/write permissions for that related folder you need to access.

Regards
x_com
0
 
LVL 8

Expert Comment

by:fozylet
ID: 9623516
The general format is

dc.Open "DBQ=" & Server.Mappath(VirtualPathToDB)  & ";Driver={Microsoft Access Driver (*.mdb)};"

x_com,
I think in this case VirtualPathToDB="/databases/ASP_GuestBook/database.mdb" as per the URL given by you.

so it should be

dc.Open "DBQ=" & Server.Mappath("/databases/ASP_GuestBook/database.mdb")  & ";Driver={Microsoft Access Driver (*.mdb)};"

i.e., without the ..

Daffy33,

Please put in
Response.Write Server.Mappath("/databases/ASP_GuestBook/database.mdb")
Response.End

in your asp page and see if it prints out the real path to DB.

0
 
LVL 29

Expert Comment

by:Göran Andersson
ID: 9623962
First of all, you need to know what the error message is.

In Internet Options, under the Advanced tab, remove the check for "Show friendly HTTP error messages".

Now, when you view the page, you will see the real error message sent from the server, instead of the friendly information page created by the browser.
0
 

Author Comment

by:Daffyy33
ID: 9626051
Thank you Guys for all you advise

x_com Re: Your last comment Comment

from x_com
Date: 10/26/2003 09:26AM PST

It did the trick, database opened , i couldn't update the databse..

But i managed to fix it

I was feeling very brain dead last night.. it seems that i wasn't taking it what you were saying,
today however BANG understood..
I must learn to  turn off the damn computer and take a break and clear my head

All is working well .. Thanks Again
0
 
LVL 29

Expert Comment

by:David H.H.Lee
ID: 9626194
you're welcome,Daffyy33.
Sometime it happend to me too, what to do? Just go to sleep until my brain get fresh again before continue.....:-)

Regards
x_com
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
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…

706 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

19 Experts available now in Live!

Get 1:1 Help Now