Solved

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

Posted on 2004-04-01
9
1,052 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

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…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
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 …

785 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