Solved

RUN TIME ERRO 70  "Permission Denied"

Posted on 2010-09-18
15
1,120 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
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 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

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
MacOS and programming in React 7 27
CONDITIONAL MAX STATEMENT IN T-SQL 3 37
Problem to error 4 43
Problem to With line 4 39
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

919 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

15 Experts available now in Live!

Get 1:1 Help Now