Solved

RUN TIME ERRO 70  "Permission Denied"

Posted on 2010-09-18
15
1,124 Views
Last Modified: 2012-06-27

Getting an error 70
Permission Denied

Trying to delete file

Please check attached code

Dim csvpath  As String
csvpath = "D:\Batco_Express\" & BNo & ".csv"

If valuelist <> "" Then
'''''''''''INSERTING DATA FROM CSV FILE to ACCESS.MDB''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''
''''''''AFTER INSERTING DATA, DELETE FILE FROM ITS ORIGINAL LOCATION
            
        Kill csvpath
End If

Open in new window

0
Comment
Question by:crystalsoft
  • 6
  • 4
  • 2
  • +1
15 Comments
 
LVL 29

Expert Comment

by:nffvrxqgrcfqvvc
ID: 33707780
The following behavior gives this error.
<:>Permission denied (Error 70)
http://msdn.microsoft.com/en-us/library/aa264534(VS.60).aspx
0
 
LVL 5

Expert Comment

by:Leithauser
ID: 33707787
I assume you opened the csv file to read from it. Are you sure you closed the file after reading data from it? If it is still open it cannot be deleted.
 
0
 
LVL 5

Expert Comment

by:Leithauser
ID: 33707803
Here is a list of causes for this error.
You tried to open a write-protected file for sequential Output or Append.

Open the file for Input or change the write-protection attribute of the file. You tried to open a file on a disk that is write-protected for sequential Output or Append.

Remove the write-protection device from the disk or open the file for Input. You tried to write to a file that another process locked. Wait to open the file until the other process releases it.

Can you show us the code you use to open and close the file?
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 1

Author Comment

by:crystalsoft
ID: 33707831
Leithauser:
Please check attached code

''''''''THIS FUNCTION IS FOR SERVER SIDE ,
''''''''ALL CSV FILES DATA WILL BE transferred TO THE DATABASE
Const adOpenStatic = 3
Const adLockOptimistic = 3
Const ForReading = 1
Const MDB_FILE = "D:\Trans.mdb"
Const TABLE_NAME = "B_Detail"
Const TABLE_COLUMNS = "BNo,Mode,BDate,....and more fileds here"

Const CSV_SEARCH_PATH = "D:\Crystal_Express"

Dim fso As New FileSystemObject
Dim objRecordSet As New ADODB.Recordset
Dim drive, objWMIService, path, line, objFile, oFile, i, props, colFiles, columns

Set objRecordSet = CreateObject("ADODB.Recordset")

objRecordSet.Open "SELECT * FROM " & TABLE_NAME, _
    con, adOpenStatic, adLockOptimistic

Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")

drive = Split(CSV_SEARCH_PATH, "\")(0)
path = "\\" & Replace(Split(CSV_SEARCH_PATH, drive + "\")(1), "\", "\\") & "\\"

Set colFiles = objWMIService.ExecQuery("Select * from CIM_DataFile where Drive='" + drive + "' and path = '" + path + "' and extension = 'csv'")

For Each oFile In colFiles
    
Set objFile = fso.OpenTextFile(oFile.Name, ForReading)

Dim valuelist
Dim BNo
For Each line In Split(objFile.ReadAll, vbNewLine)
'''        objRecordSet.AddNew
        columns = Split(TABLE_COLUMNS, ",")
        ''''''''''''''''''''''''''''''''''''''
        props = Split(line, ";")

For i = 0 To UBound(props)

If Not IsNull(props(i)) And props(i) <> "" Then

    If valuelist = "" Then
        If i = 0 Then
            BNo = props(i)
        End If
            valuelist = valuelist & "'" & props(i) & "'"
    Else
        If i = 0 Then
            BNo = props(i)
        End If
            valuelist = valuelist & ",'" & props(i) & "'"
    End If
End If

Next i
        Next
            Next
            
Dim csvpath  As String
csvpath = "D:\Crystal_Express\" & BNo & ".csv"

If valuelist <> "" Then
'''''''''''INSERTING DATA FROM CSV FILE''''''''''''''
        con.Execute "insert into B_Detail (BNo,Mode,BDate,...and all fields) values (" & valuelist & ")"
    
''''''''''''''''''''''''''''''''''''''''

Open in new window

0
 
LVL 1

Author Comment

by:crystalsoft
ID: 33707859

got solution

i added following line and its working

objFile.Close
0
 
LVL 29

Expert Comment

by:nffvrxqgrcfqvvc
ID: 33707860
Line 30: You open the file stream but never Close() it before trying to delete it.
For each file your opening you need to call .Close() in you For Each block.
Add ObjFile.Close()  @ line 59
 
0
 
LVL 5

Expert Comment

by:Leithauser
ID: 33707903
That is pretty much what I suggested above. Hint, hint. I need 100 more points this month to maintain my expert status. ;-)
0
 
LVL 1

Author Comment

by:crystalsoft
ID: 33718500

sorry for late reply

But when its going for next file its displaying run time error
run time error 91
Object variable or with block variable not set

and on debug highlighted on
objFile.Close
0
 
LVL 5

Expert Comment

by:Leithauser
ID: 33718705
<<But when its going for next file its displaying run time error
run time error 91
Object variable or with block variable not set

and on debug highlighted on
objFile.Close>>
I am confused. You say that the error occurs when you try to open the next file, but the highlight is on the objFile.Close line that the program has already passed? That does not seem possible.
What line # did you insert the Clsoe in?

0
 
LVL 1

Author Comment

by:crystalsoft
ID: 33722226
Please check attached code

This function is under timer event

1-pick a csv file and get value
2 - then insert this value into database
3 - then delete csv file

1 - Pick another csv file and get value
2 - then insert this value into database
3 - then delete csv file

go for next csv file till all csv files delete

the thing is attached code is working till delete csv file
but when its go for next csv file , error occurs
run time error 91
Object variable or with block variable not set
and highlighted on ---- >      objFile.Close


POINT incresed  :-)
Private Sub Command2_Click()

''''''''THIS FUNCTION IS FOR SERVER SIDE ,
''''''''ALL CSV FILES DATA WILL BE MOVE TO THE DATABASE
Const adOpenStatic = 3
Const adLockOptimistic = 3
Const ForReading = 1
Const MDB_FILE = "D:\Crystal\Auto_Trans\Trans.mdb"
Const TABLE_NAME = "B_Detail"
Const TABLE_COLUMNS = "BiltyNo,Mode,BDate,TruckNo,...all fields"

Const CSV_SEARCH_PATH = "D:\Crystal

Dim fso As New FileSystemObject
Dim objRecordSet As New ADODB.Recordset
Dim drive, objWMIService, path, line, objFile, oFile, i, props, colFiles, columns

Set objRecordSet = CreateObject("ADODB.Recordset")

objRecordSet.Open "SELECT * FROM " & TABLE_NAME, _
    con, adOpenStatic, adLockOptimistic

Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")

drive = Split(CSV_SEARCH_PATH, "\")(0)
path = "\\" & Replace(Split(CSV_SEARCH_PATH, drive + "\")(1), "\", "\\") & "\\"

Set colFiles = objWMIService.ExecQuery("Select * from CIM_DataFile where Drive='" + drive + "' and path = '" + path + "' and extension = 'csv'")

For Each oFile In colFiles
    
Set objFile = fso.OpenTextFile(oFile.Name, ForReading)

Dim valuelist
Dim BNo
For Each line In Split(objFile.ReadAll, vbNewLine)
'        objRecordSet.AddNew
        columns = Split(TABLE_COLUMNS, ",")
        ''''''''''''''''''''''''''''''''''''''
        props = Split(line, ";")

For i = 0 To UBound(props)

If Not IsNull(props(i)) And props(i) <> "" Then

    If valuelist = "" Then
        If i = 0 Then
            BNo = props(i)
        End If
        valuelist = valuelist & "'" & props(i) & "'"
    Else
        If i = 0 Then
            BNo = props(i)
        End If
        
        valuelist = valuelist & ",'" & props(i) & "'"
    End If

End If

Next i

objFile.Close

If valuelist <> "" Then
'''''''''''INSERTING DATA FROM CSV FILE'''''''''''''
        con.Execute "insert into B_Detail (BiltyNo,Mode,BDate,..and rest of the columns) values (" & valuelist & ")"
        Kill "D:\Crystal\" & BNo & ".csv"
        valuelist = Empty
        
End If
        Next
            Next

Open in new window

0
 
LVL 5

Accepted Solution

by:
Leithauser earned 350 total points
ID: 33725731
Because the objFile.Close like is within the
For Each line In Split(objFile.ReadAll, vbNewLine)
loop, you are calling this  line again before you reopen it in line 32. This causes the error because once you close it, objFile does not exist anymore. It is hard to understand exactly what you are doing, but it looks to me like the Next in line 72 should be earlier, like about line 62. That, or move the
For Each line In Split(objFile.ReadAll, vbNewLine)
to between lines 36 and 37 so that it is executed again for each reinteration of the loop.
0
 
LVL 5

Expert Comment

by:Leithauser
ID: 34019839
It seems to me that my last comment answers the question and solves the problem.
0
 

Expert Comment

by:South Mod
ID: 34067927
Implementing Expert recommendation

SouthMod
Community Support Moderator
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VbScript to countdown to New Year's Day 6 65
MS Access 03, TransferText, decimal places 8 78
What are programming codes and how do they work? 7 103
Vector, list Questions R 6 31
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

839 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