ASP database access in the routing problem

  Its peacetime use to do most of the website is SQL database, ACCESS database on the use of the website do not have too much contact.    Yesterday in a group of friends to use the website background ACCESS database management procedures, and has encountered some troubles. 

  The website directory settings as follows (listed only the relevant part) 

  F1 directory is the background of the management procedures, MYDATA.MDB F2 is the directory database files, CNN.ASP states that the database connectivity, in other documents in the document to include ways to use. 

  CNN.ASP because MYDATA.MDB and in the same directory, CNN.ASP the link is so written statement: 

  StrCnn = "= (driver microsoft access driver (*. mdb)); dbq =" & _ 

  Server.Mappath ( "mydata.mdb") 

  Because it is the original written, I did not carefully consider what, in F1 directory directly under the INDEX.ASP statements in the document to join F2 

  <!–# Include file ="../ F2/Cnn.asp "-> 

  Then run…… ah?    ?    ?    Wrong!    ! 

  Microsoft OLE DB Provider for ODBC Drivers (0×80004005) 
  [Microsoft] [ODBC Microsoft Access Driver] Common Mistakes can not open registry keyword 'Temporary (volatile) Jet DSN for process 0×94 Thread 0×9a0 DBC 0×13b0074 Jet'. 

  OPEN errors in the database error, and did not find the database.    Is the database is wrong path? 

  CNN.ASP will look at the output in the first strCnn 

  Driver = (microsoft access driver (*. mdb)); dbq = C: \ F1 \ mydata.mdb 

  Sure enough, the wrong path! 

  It appears that it is this Server.MapPath CNN.ASP document will contain pages of the document path to the current path to do.    If F1 is that the directory contains CNN.ASP INDEX.ASP, at the Server.MapPath ( "mydata.mdb") is C: \ F1 \ mydata.mdb If F1 directory of a directory NEWS document contains CNN.ASP, at the Server.MapPath ( "mydata.mdb") is C: \ F1 \ News \ mydata.mdb; 

  Proven that the above situation indeed. 

  Found the problem, the solution to it.    Because not limited to the several stages of the directory to include CNN.ASP document, it will not be able to use access to the database Server.MapPath correct path; Are we going to use the database of all the documents into the database all the connections?    This is the worst choice, try to avoid. 

  After N-minute thinking, and finally come up with a more cost-effective way to do this is not the use of virtual path, first determine the actual root directory path, and then join the path of the database.    Codes are as follows: 

  Cnn.asp documents: 

  Dim strCurPath, strCurLocation 

  'Access to the document contains pages of documents virtual path 

  StrCurPath = Request.ServerVariables ( "PATH_INFO") 

  'Access to the pages of the document contains the actual document path 

  StrCurLocation = Request.ServerVariables ( "PATH_TRANSLATED") 

  'Migration path interval symbol (virtual path "/" separated, the actual path "\" separation) 

  StrCurPath = Replace (strCurPath ,"/"," \ ") 

  'Root directory site by the actual path 

  StrCurLocation = Replace (strCurLocation, strCurPath, "") 

  'Designated database actual path 

  StrCurLocation strCurLocation & = "\ F2 \ MyData.mdb" 

  Set Cnn = Server.CreateObject ( "ADODB.CONNECTION") 

  'Connect to the database server, database name mydata.mdb 

  StrCnn = "= (driver microsoft access driver (*. mdb)); dbq =" & strCurLocation 

  Cnn.Open strCnn 

  On these, it Rengzhuantou 

Bookmark it: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • Sphinn
  • del.icio.us
  • Google
  • DotNetKicks
  • DZone
  • Furl
  • Netvouz

Tags: , ,

Releated Articles


0 Comments to “ASP database access in the routing problem”

No Comments. Send your comment.

Leave a Reply

You must be logged in to post a comment.