473,379 Members | 1,544 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Error: The process cannot access the file it si being used by anot

I am just starting developing with .Net(Have used asp for years). I have
created a very simple upload page which once uploaded opens the file(excel)
and displays the data. If I Attempt to re-run using the same file I get the
message 'Error: The process cannot access the file because it is being used
by another process. '

VS 2005

Here is my code, any suggestions...

<%@ Page Language="VB" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>

<script runat="server">

Private Sub Page_Load()
If Not IsPostBack Then Response.Write("Please Select a File.")
End Sub
Private Sub Submit1_ServerClick(ByVal sender As Object, ByVal e As
System.EventArgs)
Dim i As Integer, max As Integer
If Not File1.PostedFile Is Nothing And
File1.PostedFile.ContentLength > 0 Then
Dim fn As String =
System.IO.Path.GetFileName(File1.PostedFile.FileNa me)
Dim SaveLocation As String = ("c:\inetpub\wwwroot\asp\Data\") & fn
Try
File1.PostedFile.SaveAs(SaveLocation)
Response.Write("The file has been uploaded.<br>")
'now get the data from the excel file and put in the db
Dim strConn As String = "Provider=Microsoft.Jet.OleDb.4.0;" _
& "data source=c:\inetpub\wwwroot\asp\data\" & fn
& ";" _
& "Extended Properties=Excel 8.0;"
Dim objConn As New OleDbConnection(strConn)
Dim strSql As String = "Select * From Prices"
Dim objCmd As New OleDbCommand(strSql, objConn)
objConn.Open()
Dim objReader As OleDbDataReader
objReader = objCmd.ExecuteReader()
If objReader.HasRows Then
'get field count
max = objReader.FieldCount
'output headings

'getvalues
While objReader.Read()
For i = 0 To max - 1
Response.Write(objReader(i).ToString & "<br>")
Next
End While
'clean up
objReader = Nothing
objCmd = Nothing
objConn = Nothing
Else
Response.Write("NO Data Found.")
End If
Catch Exc As Exception
Response.Write("Error: " & Exc.Message)
End Try
Else
Response.Write("Please select a file to upload.")
End If
File1 = Nothing
End Sub
</script>
<html>
<head>
</head>
<body>
<form id="Form1" method="post" enctype="multipart/form-data"
runat="server">
<input id="File1" type="file" name="File1" runat="server" />
<br />
<input id="Submit1" type="submit" value="Upload" runat="server"
onserverclick="Submit1_ServerClick" />
</form>
</body>
</html>
<script language=vbscript>
function form1_onsubmit()
if right(form1.file1.value,4)<>".xls" then alert "Excel Files
Only.":form1_onsubmit=false
end function
</script>

Feb 24 '06 #1
1 3250
Hi Adeturner,

Welcome to the ASP.NET newsgroup.

As for the "Error: The process cannot access the file because it is being
used by another process. " error, it is likely caused by the uploaded excel
file be locked by the ASP.NET application process. From the code snippet
you provided, you used the below code to clear the datareader and
connection after finishing the data reading operation:

================
'clean up
objReader = Nothing
objCmd = Nothing
objConn = Nothing
=================

, however, these statements only make those data objects ready for garbage
collection rather than actually release the underlying data connection. For
"DataReader" and "Connection" object of ADO.NET, we should always call the
".Close()" function of them after we finish using them. Therefore, you can
try adding the Close statements for the "OleDbDataReader" and
OleDbConnection in your page code to see whether it helps.

If there're any other problems, please also feel free to post here.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Feb 27 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: JeffM | last post by:
I have a .dat file on a remote server that seems to be locked. I have tried to FTP to it and delete it, rename it, copy over it and I get the error. "Could not copy temporary files to the output...
2
by: lucy | last post by:
Hi, I use ADOX to create a Access database programmatically from my asp.net application and save ".mdb" file to a temp folder under my project foler on the web server. After database is created...
5
by: ZWeng | last post by:
I created a windows service using FileSystemWatcher to moniter a folder for file drops. The service uses FileStream and StreamReader to read and process the file. After it is done, the file is...
0
by: HKSHK | last post by:
This list compares the error codes used in VB.NET 2003 with those used in VB6. Error Codes: ============ 3: This Error number is obsolete and no longer used. (Formerly: Return without GoSub)...
0
by: imranabdulaziz | last post by:
Dear All, I am making web application using Asp.net C#(Visual Studio2005). And Sql server 2005 as a back End I generated local mode report but as there was no printing option available . I assign...
0
by: =?Utf-8?B?QWxoYW1icmEgRWlkb3MgS2lxdWVuZXQ=?= | last post by:
Hello, mister I have an application web asp.net 2.0 + vs 2005 and VS 2005 Web Application Project. Its appears this error in execution: "Cannot Create/Shadow Copy '<projectname>' when that...
1
by: sdanda | last post by:
When I build my application it gets this error.My application is sample "Error 1 Unable to copy file "obj\Debug\sample.exe" to "bin\Debug\sample.exe". The process cannot access the file...
0
by: Tim Golden | last post by:
aditya shukla wrote: Why on earth are you *specifying* c:\python25 as the directory for this file? It's automatically created in your user-specific temp directory which has specific permissions...
10
by: happyse27 | last post by:
Hi All, I got this apache errors(see section A1 and A2 below) when I used a html(see section b below) to activate acctman.pl(see section c below). Section D below is part of the configuration...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.