Solved

Using FreeASPUpload & Inserting Record at same time

Posted on 2010-09-17
6
1,822 Views
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) http://www.experts-exchange.com/Web_Development/Software/Macromedia_Dreamweaver/Q_26465103.html.  
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: http://www.webfilebrowser.com/



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>

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

    </form>

<%

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

    Err.Clear

    testFile.Close

    fso.DeleteFile(fileName)

    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

    Err.Clear

    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

    Upload.Save(uploadsDirVar)



    ' 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 & "http://www.mywebsite.co.uk/tempUploads/" & 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 & ")"

  

                cn.Execute(sql)

        

        next

                    

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

                cn.Close

                Set cn = nothing

        

    else

        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

%>



<HTML>

<HEAD>

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

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

<style>

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

</style>

<script>

function onSubmitForm() {

    var formDOMObj = document.frmSend;

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

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

    else

        return true;

    return false;

}

</script>



</HEAD>



<BODY>



<br><br>

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

    else

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

        OutputForm()

        response.write "</div>"

    end if

else

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

    OutputForm()

    response.write SaveFiles()

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

end if



%>







</BODY>

</HTML>

Open in new window

0
Comment
Question by:FSAAdmin
  • 4
  • 2
6 Comments
 
LVL 3

Accepted Solution

by:
giuseppepi earned 50 total points
ID: 33710615
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 http://www.mywebsite.co.uk/FacilitiesPlan.accdb
If not we will check everything step by step.
Regards, Giuseppe
0
 

Author Comment

by:FSAAdmin
ID: 33716554
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
0
 

Author Comment

by:FSAAdmin
ID: 33717801
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

				MyConnection.Execute(MySQLStatement)

				MyConnection.Close()

				

				Response.Write ("Record inserted")

				Set MyConnection = Nothing

Open in new window

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.

 
LVL 3

Assisted Solution

by:giuseppepi
giuseppepi earned 50 total points
ID: 33722763
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.
0
 

Author Comment

by:FSAAdmin
ID: 33725308
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.  
0
 

Author Closing Comment

by:FSAAdmin
ID: 33773052
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.
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
Creating TABS in ASP Classic NOT using DIV 22 63
Update field in order 21 122
Copy only dates 3 80
Server Timeout with Loop 6 38
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 tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

910 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

24 Experts available now in Live!

Get 1:1 Help Now