Uploading files

  • Im trying to create a page which will allow users to upload files which are then stored as images in the database. I have a webserver which has all the webpages and a dataserver which holds the table where I want to store the image.

    When I try using the FileUploader class and a recordset the problem I get is that it wont let me save into the dataserver table but I tested and it lets me save to a webserver table.

    For Each File In Uploader.Files.Items

    Set RS = Server.CreateObject("ADODB.Recordset")

    rs.Open "select * from dataserver.dataserver.dbo.test",conn,2,2

    RS.AddNew

    File.SaveToDatabase

    RS("filedata")

    Next

    I also tried using an ADODB.Stream object and this lets me save into the dataserver table but the myStream.LoadFromFile line does not work saying it cant open the file. The page would get the path of the file they are trying to upload from the previous page but ive just hardcoded it to test.

    Set myStream = Server.CreateObject("ADODB.Stream")

    Set myCommand = Server.CreateObject("ADODB.Command")

    myStream.Type = adTypeBinary

    myStream.Open

    myStream.LoadFromFile "c:\test.txt"

    Set myCommand = Server.CreateObject("ADODB.Command")

    myCommand.CommandText = "INSERT INTO dataserver.dataserver.dbo.test VALUES(?)"

    What is the best way to upload a file to a database?

  • Ive noticed that with the recordset the problem is that the locktype and cursor are changing pessimistic to read only and dynamic to forward only.

    Does anyone know why it would be doing this?

  • The version using Stream is best, imo. The problem might be that the account running ASP does not have access to the local file you have specified.

  • When I try uploading the other way the ASP is able to the access the local file specified, its only when using Stream that it cant open it.  

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply