Using FreeASPUpload & Inserting Record at same time

Posted on 2010-09-17
Last Modified: 2012-05-10
I had previously posted a question on how to upload a file and insert a record (2 actions with one button)  
I thought a more appropriate title would help in getting this resolved since I'm using FreeASPUpload to upload the file.

I came across the FreeASPUpload.  Before using FreeASPUpload, I was able to save a record to the database with the file name store in a field called "Attachment".    

Since I want the users to be able to retrieve the attachment later, I also need to use FreeASPUpload to upload the file.  I'm at the point now where I can upload the file but I'm getting an error when trying to insert the record.

I've read through a handful of questions and solutions on this forum where others have been trying to do the same thing.  However I am unable to determine the clear solution.

I am now getting an error on line 93 saying that it could not find the file / database.  I have given full  permissions to the guest account on the folder where the database resides.  

So now it seems that i need help getting the insert statement to work.
<%@ Language=VBScript %>


option explicit 

Response.Expires = -1

Server.ScriptTimeout = 600

' All communication must be in UTF-8, including the response back from the request

Session.CodePage  = 65001


<!-- #include file="freeaspupload.asp" -->


  ' ****************************************************

  ' Change the value of the variable below to the pathname

  ' of a directory with write permissions, for example "C:\Inetpub\wwwroot"

  ' ****************************************************

  Dim uploadsDirVar

  uploadsDirVar = "c:\inetpub\wwwroot\FacilityConditionTracking\files" 


  ' Note: this file uploadTester.asp is just an example to demonstrate

  ' the capabilities of the freeASPUpload.asp class. There are no plans

  ' to add any new features to uploadTester.asp itself. Feel free to add

  ' your own code. If you are building a content management system, you

  ' may also want to consider this script:

function OutputForm()


    <form name="frmSend" method="POST" enctype="multipart/form-data" accept-charset="utf-8" action="uploadTester4.asp" onSubmit="return onSubmitForm();">

	<B>File names:</B><br>

    File 1: <input name="attach1" type="file" size=35><br>


	<!-- These input elements are obviously optional and just included here for demonstration purposes -->

	<B>Additional fields (demo):</B><br>

	Enter an AiM Work Order Number: <input type="text" name="AimWO"><br>

    <input style="margin-top:4" type=submit value="Upload">



end function

function TestEnvironment()

    Dim fso, fileName, testFile, streamTest

    TestEnvironment = ""

    Set fso = Server.CreateObject("Scripting.FileSystemObject")

    if not fso.FolderExists(uploadsDirVar) then

        TestEnvironment = "<B>Folder " & uploadsDirVar & " does not exist.</B><br>The value of your uploadsDirVar is incorrect. Open uploadTester.asp in an editor and change the value of uploadsDirVar to the pathname of a directory with write permissions."

        exit function

    end if

    fileName = uploadsDirVar & "\test.txt"

    on error resume next

    Set testFile = fso.CreateTextFile(fileName, true)

    If Err.Number<>0 then

        TestEnvironment = "<B>Folder " & uploadsDirVar & " does not have write permissions.</B><br>The value of your uploadsDirVar is incorrect. Open uploadTester.asp in an editor and change the value of uploadsDirVar to the pathname of a directory with write permissions."

        exit function

    end if




    If Err.Number<>0 then

        TestEnvironment = "<B>Folder " & uploadsDirVar & " does not have delete permissions</B>, although it does have write permissions.<br>Change the permissions for IUSR_<I>computername</I> on this folder."

        exit function

    end if


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

    If Err.Number<>0 then

        TestEnvironment = "<B>The ADODB object <I>Stream</I> is not available in your server.</B><br>Check the Requirements page for information about upgrading your ADODB libraries."

        exit function

    end if

    Set streamTest = Nothing

end function

function SaveFiles

    Dim Upload, fileName, fileSize, ks, i, fileKey

    Set Upload = New FreeASPUpload


    ' If something fails inside the script, but the exception is handled

    If Err.Number<>0 then Exit function

    SaveFiles = ""

    ks = Upload.UploadedFiles.keys

    if (UBound(ks) <> -1) then

    response.write "<h3>Upload Success!</h3>"

        SaveFiles = "<B>You have successfully uploaded:</B> "


                Dim CurrentTime

                CurrentTime = NOW()

                Dim cn,sql,theFile,sFileTitle

                Set cn = Server.CreateObject("ADODB.Connection")

                cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="& Server.MapPath("FacilitiesPlan.accdb") 


        for each fileKey in Upload.UploadedFiles.keys


                SaveFiles = SaveFiles & Upload.UploadedFiles(fileKey).FileName & " <br>"

               ' SaveFiles = SaveFiles & "<br>You can view this document here: "    

                'SaveFiles = SaveFiles & "" & Upload.UploadedFiles(fileKey).FileName



                theFile = Upload.UploadedFiles(fileKey).FileName ' the filename of the actual file

                sFileTitle = Upload.Form(Upload.UploadedFiles(fileKey) & "_name") ' what the user entered in the filename field


                'insert query


                sql = "Insert into NotedIssues(attachment,AiMWO) values (" _

                & "'" & attach1 & "', " _

                & "'" & AiMWO & ")"






                'Now that we have displayed the table data lets close the connection


                Set cn = nothing



        SaveFiles = "The file name specified in the upload form does not correspond to a valid file in the system."

    end if

    'SaveFiles = SaveFiles & "<br>Enter a number = " & Upload.Form("enter_a_number") & "<br>"

    'SaveFiles = SaveFiles & "Checkbox values = " & Upload.Form("checkbox_values") & "<br>"

end function




<TITLE>Test Free ASP Upload 2.0</TITLE>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />


BODY {background-color: white;font-family:arial; font-size:12}



function onSubmitForm() {

    var formDOMObj = document.frmSend;

    if (formDOMObj.attach1.value == "")

        alert("Please press the Browse button and pick a file.")


        return true;

    return false;






<div style="border-bottom: #A91905 2px solid;font-size:16">Upload files to your server</div>


Dim diagnostics

if Request.ServerVariables("REQUEST_METHOD") <> "POST" then

    diagnostics = TestEnvironment()

    if diagnostics<>"" then

        response.write "<div style=""margin-left:20; margin-top:30; margin-right:30; margin-bottom:30;"">"

        response.write diagnostics

        response.write "<p>After you correct this problem, reload the page."

        response.write "</div>"


        response.write "<div style=""margin-left:150"">"


        response.write "</div>"

    end if


    response.write "<div style=""margin-left:150"">"


    response.write SaveFiles()

    response.write "<br><br></div>"

end if




Open in new window

Question by:FSAAdmin
  • 4
  • 2

Accepted Solution

giuseppepi earned 50 total points
Comment Utility
According to your code the DB is located in the root of the website. Is this correct?
The best practice should be to create a special folder for the DB, giving write permissions.
In addition some server (windows 2008 first of all) are not allowing users to access files that has not been mapped returning 404 code.
Anyway, again, make sure that your DB is not located at
If not we will check everything step by step.
Regards, Giuseppe

Author Comment

Comment Utility
I created a folder Database and still get the same error message but now it points to the new location of the database.  

I also gave Full Control to the guest account.

Microsoft JET Database Engine error '80004005'

Could not find file 'C:\Inetpub\wwwroot\FacilityConditionTracking\Database\FacilitiesPlan.accdb'.

/FacilityConditionTracking/uploadTester3.asp, line 93

Author Comment

Comment Utility
I receive a different error after changing my connection string receive a different error.

Microsoft JET Database Engine error '80040e4d'

Cannot start your application. The workgroup information file is missing or opened exclusively by another user.

/FacilityConditionTracking/uploadTester3.asp, line 101

MyConnection.Open MyConnectionString
Dim MyConnection

				Dim MyConnectionString

				Dim MySQLStatement


				MyConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" &_

				"Data Source=C:\Inetpub\wwwroot\FacilityConditionTracking\Database; User ID=;Password="       

				MySQLStatement = "INSERT INTO NotedIssues (AiMWO) Values ('166777')"


				Set MyConnection = Server.CreateObject("ADODB.Connection")

				MyConnection.Open MyConnectionString




				Response.Write ("Record inserted")

				Set MyConnection = Nothing

Open in new window

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline


Assisted Solution

giuseppepi earned 50 total points
Comment Utility
The file is opened by another user (the lock file is somehow preset)

Anyway there are several causes for this error message:
1- The account that Microsoft Internet Information Server (IIS) is using (which is usually IUSR) does not have the correct Windows NT permissions for a file-based database or for the folder that contains the file.
The file and the data source name are marked as Exclusive.
2- Another process or user has the Access database open.
The error may be caused by a delegation issue. Check the authentication method (Basic versus NTLM), if any. If the connection string uses the Universal Naming Convention (UNC), try to use Basic authentication or an absolute path such as C:\Mydata\Data.mdb. This problem can occur even if the UNC points to a resource that is local to the IIS computer.
3- This error may also occur when you access a local Microsoft Access database that is linked to a table where the table is in an Access database on a network server.

Author Comment

Comment Utility
I am able to upload the file and write literal values to the database.  However, now I'm stuck trying to read the variables entered on the form and inserting them into the database.  

Author Closing Comment

Comment Utility
Thank you for looking at this.  It turns out the problem was due to several database setup errors including the use of the column "Level" which I found out was a reserved word.  I was also forced to enter a date and programmatically code the value of a checkbox.

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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 demonstration started out as a follow up to some recently posted questions on the subject of logging in: and…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

772 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