Solved

ASP Upload (using Persits ASPUpload) error when uploading from UNC Paths.

Posted on 2004-04-01
9
1,049 Views
Last Modified: 2007-12-19
Hello,

I am using ASP Upload to insert files into a SQL 2000 database via an ASP form.  It works fine when uploading files which are stored on the same computer which is being used to access the form, but when I try and upload files via a UNC path from a shared computer.  The error I get is below:

Error saving the file: [Microsoft][ODBC SQL Server Driver]COUNT field incorrect or syntax error


The source from the ASP page (at least the section which does the work) is as follows:

<%
Set Upload = Server.CreateObject("Persits.Upload")

if request("CN") <> "" then
     CN     = request("CN")
else
     Upload.Save "C:\temp"
     CN = Upload.form("cn")
end if
if Upload.form("upd") = "1" then
      Set File = Upload.Files("FileContent")

     if not File is nothing then
     FileType = Upload.form("FileType")
     if Upload.Form("description") = "" then description = "NULL" else description = "'"&RmAps(Upload.Form("description"))&"'"
          sqlStmt = "insert into Files (CN, Date, CreatedBy, Description, FileName, FileType, FileSize, FileContent) values "&_
                    "(" & CN & "," &_
                    " getdate(), " &_
                    "1, " &_
                    ""&description&", " &_
                    "'" & File.extractfilename & "', " &_
                    ""&FileType&", " &_
                    "" & File.Size & ", " &_
                    "?);"
         
          on error resume next
          File.ToDatabase Application("Conn"), SqlStmt
          if Err <> 0 Then
               Response.Write "<font color=RED>Error saving the file: " & Err.Description & "</font><br>"
          Else
               File.Delete
               response.write "<script>"
               response.write "window.open (""c.asp?cn="&cn&""", 'Main_App')"
               response.write "</script>"
          end if    

     else
          response.write "<font color=RED>ERROR - FILE NOT UPLOADED.</font><br><br>Please try again."
     end if          
end if
%>

Thanks for help in advance!

BTW there is another question exactly like this one from me that you can get points from if you answer this one right!
0
Comment
Question by:electricd7
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 11

Expert Comment

by:Slimshaneey
Comment Utility
Looks like a problem with the insert here:

Try this:
sqlStmt = "insert into Files (CN, Date, CreatedBy, Description, FileName, FileType, FileSize, FileContent) values "&_
                    "(" & CN & "," &_
                    " getdate(), " &_
                    "1, " &_
                    ""&description&", " &_
                    "'" & File.extractfilename & "', " &_
                    ""&FileType&", " &_
                    "" & File.Size & ", '" &_
                    "?');"
0
 
LVL 11

Expert Comment

by:Slimshaneey
Comment Utility
I think there should also be quotes around description.... and also FileType if it is not an integer type(I ahve not put any in)::

sqlStmt = "insert into Files (CN, Date, CreatedBy, Description, FileName, FileType, FileSize, FileContent) values "&_
                    "(" & CN & "," &_
                    " getdate(), " &_
                    "1, " &_
                    "'" & description & "', " &_
                    "'" & File.extractfilename & "', " &_
                    ""&FileType&", " &_
                    "" & File.Size & ", '" &_
                    "?');"
0
 

Author Comment

by:electricd7
Comment Utility
No the quotes are all fine.  They match the datatypes.  Sorry, forgot to mention that.  The ? at the end is specific to the "File.ToDatabase" line in my code.  Again this code works fine when not using UNC paths for the file upload.  Thanks.
0
 
LVL 11

Expert Comment

by:mouatts
Comment Utility
I'm wondering if sql server is misreading the \\ at the start of the UNC as something else (escaping it out for example).
Two suggestions firstly upload the same file once using a drive letter and once using UNC that will prove that it is UNC one way or another.
Secondly try replaceing \\ characters with something when you extract the filename just to establish if this is the problem.

Steve
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:electricd7
Comment Utility
Actually I created a mapped drive to the UNC path thinking the exact same thing, and had the same results.  It can actually extract the filename, and I see an empty file created on the server, but for some reason the file.content is never created.

ED7
0
 
LVL 11

Expert Comment

by:mouatts
Comment Utility
Try changing the upload.save to a upload.SaveToMemory. I'm wondering if it is try to create the file with the UNC bits in, which I guess might actually work if the UNC address is valid but you might not see it as it will overwrite the original file.

Steve
0
 

Author Comment

by:electricd7
Comment Utility
Just changed it and it immediately did the same thing.  Its like it doesn't even begin to load the file if it is over UNC.  I know that it is supposed to support it, but i'm stumped.  Anyone have ASP Upload that can verify UNC uploading?
0
 
LVL 28

Expert Comment

by:sybe
Comment Utility
I have written my own file-upload script (pure-asp). And i can imagine that the guys who created "Persits.Upload" forgot to check fileuploading from UNC path. The path looks different, so the filename is not being parsed correctly. I suggest you use another component.

btw - pure-script fileupload doesnot seem to be slower then component-based fileupload: http://www.taka.nl/programming/asp/comparing_fileupload.asp

http://www.aspfaq.com/show.asp?id=2189
0
 
LVL 11

Accepted Solution

by:
mouatts earned 500 total points
Comment Utility
Ok well I tested this on a site of mine and it worked with a UNC (I don't know why I didn't think of this sooner).
The main differences are that my code does a upload.savevirtual (I do seem to recall I had some problems with upload.save), I don't write into a database and I never do a set file I always use upload.files("filecontent"). syntax.

I'd try a savevirtual as your first step.
BTW in case you haven't checked I also looked at origainalpath and it did contain a valid UNC.

Steve
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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 …
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
This video discusses moving either the default database or any database to a new volume.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

763 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

11 Experts available now in Live!

Get 1:1 Help Now