Solved

RUN TIME ERRO 70  "Permission Denied"

Posted on 2010-09-18
15
1,118 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
 
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
mapShare challenge 13 68
delphi parse string to params 3 81
move one pixel 4 41
Add and format columns in vb6 7 20
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…
A short article about problems I had with the new location API and permissions in Marshmallow
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

707 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

13 Experts available now in Live!

Get 1:1 Help Now