?
Solved

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

Posted on 2004-04-01
9
Medium Priority
?
1,063 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 11

Expert Comment

by:Slimshaneey
ID: 10732772
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
ID: 10732797
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
ID: 10732988
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 11

Expert Comment

by:mouatts
ID: 10733275
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
 

Author Comment

by:electricd7
ID: 10733395
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
ID: 10733499
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
ID: 10733766
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
ID: 10738670
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 2000 total points
ID: 10743125
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
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…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

765 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