Results 1 to 5 of 5

Thread: asp connection by using fixed path ??

Threaded View

  1. #2
    PowerPoster
    Join Date
    May 2006
    Posts
    2,988

    Re: asp connection by using fixed path ??

    If the DB file is located on another server, you will have to download it first, save it on your server, then open it up. This is actually easy.

    If it is located on your server, then you could just get the URL path .. even better .. Server.Mappath("./MyFolder/MyFile.mdb")

    here is an ASP page I just knocked together that downloads a remote file, saves it to the server (i used a folder called _tmp in this example), and also gets the Response Header of the request, meaning if the page is not found or the page has an error in it for some reason it will show an error .. if not it will show it was downloaded .. that is the part where you would then open the file and do what you want to it ..

    Files are saved with the prefix "tmp' and then the time and date and the file extension .. in this case ".mdb"

    Change the Constants at the top to your own settings.

    Rory

    Code:
    <%@ Language="VBScript" %> 
    <%
    Option Explicit
    
    '// SET RESPONSE HEADERS
    Response.Buffer = True
    Response.Expires = 0
    Response.ExpiresAbsolute = Now() - 1
    Response.AddHeader "cache-control","private"
    Response.AddHeader "pragma", "no-cache"
    
    '// 5 MINUTE TIMEOUT
    Server.ScriptTimeout = 300
    
    Dim strFile
    Dim strText
    Dim strStatus
    Dim strResults
    
    '// FILE TO DOWNLOAD
    Const strSource = "http://www.myurl.com/database/mydb.mdb"
    
    '// FOLDER TO SAVE TO (set permissons on this!!)
    Const strFolder = "_tmp"	
    
    '// RESPONSE TURNED ON
    Const blnResponse = True
    
    
    '// SUB TO DOWNLOAD FILE
    Sub DownloadFile(byRef strTemp)
    
    	Dim strDate, strTime
    	Dim objHttp, objStream
    	
    	Const adTypeBinary = 1
    	Const adSaveCreateOverWrite = 2
    
    	On Error Resume Next
    
    	'// CREATES TEMPORARY FILE
    	strDate = Day(Date) & Month(Date) & Year(Date)
    	strTime = Hour(Time) & Minute(Time) & Second(Time)
    	strTemp = Trim(replace("tmp" & strTime & strDate & ".mdb"," ",""))
    	strTemp = Server.Mappath("./" & strFolder & "/" & strTemp)
    
    	'// SHOW RESPONSE
    	If CBool(blnResponse) Then
    		Response.Write "<b>Downloading Remote File.</b>  " & vbCrLf
    		Response.Write "Please Wait .." & vbCrLf
    		Response.Flush
    	End If
    	
    	'// DOWNLOAD THE PAGE
    	Set objHttp = Server.CreateObject("Msxml2.ServerXMLHTTP")
    	objHttp.Open "GET", strSource, False
    	objHttp.Send ""
    	strStatus = objHttp.Status
    	strResults = objHttp.StatusText
    	
    	'// SAVE TO LOCAL SERVER
    	Set objStream = Server.Createobject("Adodb.Stream")
    	objStream.Type = adTypeBinary
    	objStream.Open
    	objStream.Write objHttp.ResponseBody
    	objStream.Savetofile strTemp, adSaveCreateOverWrite
    	objStream.Close
    
    	'// CLOSE OBJECTS
    	Set objStream = Nothing
    	Set objHttp = Nothing
    	
    	'// SHOW ERROR & END
    	If err <> 0 Then
    		Response.Write "<br><font color=""red""><b>Error " & Err.Number & ".</b>  " & vbCrLf
    		Response.Write Err.Description & "</font>" & vbCrLf
    		Response.End
    	End If
    
    End Sub
    
    '// DOWNLOAD NOW
    Call DownloadFile(strFile)
    
    '// IF RESPONSE ERROR
    If strStatus >= 400 And strStatus <= 599 Then
    	Response.Write "<br><font color=""red""><b>Error " & strStatus & ".</b>  " & vbCrLf
    	Response.Write strResults & "</font>" & vbCrLf
    	Response.End
    Else
    '// ELSE OPEN FILE TO WORK ON
    	Response.Write "<br><b>Download Complete</b>" & vbCrLf
    End If
    %>
    Last edited by rory; Jun 10th, 2006 at 06:35 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width