Solved

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

Posted on 2004-04-01
9
1,050 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
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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How can i convert a Generic list to DataTable in c# 3 724
Update Stored Procedure question 8 48
Classic ASP - cannot get to correct path 17 66
SP to delete duplicates 15 60
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

932 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

19 Experts available now in Live!

Get 1:1 Help Now