|
-
Nov 14th, 2005, 02:56 AM
#1
Thread Starter
Addicted Member
Streamreader close error
Hi all,
I am using a streamreader to read txt files. This all works fine, but once it's done, I want to copy the text file to another location. In order to do this, I should close the streamreader, in order for the system to release the txt file right?
Well, this seems not to be working. I call streamreader.close.... but it doesn't release my txt file...
This is some of my code:
VB Code:
Select Case whatToDo
Case "V"
theFile.Delete()
Case "B"
sr.Close()
IO.File.Move("C:\Netcash\DebitProcessor\2_Verification\" & theFile.Name, "C:\Netcash\DebitProcessor\3_MasterBatch\" & theFile.Name)
Case "C"
sr.Close()
IO.File.Move("C:\Netcash\DebitProcessor\2_Verification\" & theFile.Name, "C:\Netcash\DebitProcessor\3_MasterBatch\" & theFile.Name)
End Select
and this is my error:
An unhandled exception of type 'System.IO.IOException' occurred in mscorlib.dll
Additional information: The process cannot access the file "C:\3_MasterBatch\19642632673021796427000.txt" because it is being used by another process.
Thanks
-
Nov 14th, 2005, 03:46 AM
#2
Re: Streamreader close error
Could be the system hasn't had time to finish writing the file.
After your close, you could add a line:
GC.Collect()
And see if it helps. This will manually force the Garbage collection to free up resources in use. I have had it help in the past with access issues.
Bill
-
Nov 14th, 2005, 03:57 AM
#3
Thread Starter
Addicted Member
Re: Streamreader close error
Hey there,
I called gc.collect... but I still have the same problem.
What else?
This is my code thusfar:
VB Code:
Dim SRead As New IO.StreamReader("C:\DebitProcessor\2_Verification\" & theFile.Name)
'OFile.OpenText("C:\DebitProcessor\2_Verification\" & theFile.Name)
''SR = New IO.StreamReader("C:\DebitProcessor\2_Verification\" & theFile.Name)
strLine = SRead.ReadLine()
strLine = SRead.ReadLine()
strLine = SRead.ReadLine()
theProgressCount = 2
Do While Not strLine Is Nothing
LineArray = Split(strLine, """,""", -1)
theProgressCount = theProgressCount + 1
For i = 0 To UBound(LineArray)
theFieldValue = Replace(LineArray(i), """", "")
SRead.Close()
GC.Collect()
If ErrorDetected = True Then
theErrorString = theErrorString & "Please check your documentation to see the explanation for the error codes." & vbCrLf & vbCrLf & "Thank You" & vbCrLf & ""
Mailer.SendMail(ReplyMail, ReplyMail, "103 CDV Check return from Netcash. ", "Your data has failed the CDV check. Below you will see the records that have failed." & vbCrLf & vbCrLf & theErrorString)
Mailer.SendMail(SupportMail, SupportMail, "103 CDV Check return from Netcash. ", "Your data has failed the CDV check. Below you will see the records that have failed." & vbCrLf & vbCrLf & theErrorString)
'Select Case Err.Number
' Case 0 'no error
' 'MsgBox("allok")
' Case Else
' MsgBox("An error occurred: " + Err.Description + " " + Err.Number + " " + Err.HelpContext)
' End
'End Select
Else
Mailer.SendMail(ReplyMail, ReplyMail, "102 CDV Check Complete. Updates and/or Batch queued to follow. ", "Your File has run through the CDV successfully. Please remember that if you have sent us a batch instruction, that it will need to be authorized online. " & vbCrLf & vbCrLf & "Thank You" & vbCrLf & "Netcash")
'Mailer.SendMail(SupportMail, SupportMail, "102 CDV Check Complete. Updates and/or Batch queued to follow. ", "Your File has run through the CDV successfully. Please remember that if you have sent us a batch instruction, that it will need to be authorized online. " & vbCrLf & vbCrLf & "Thank You" & vbCrLf & "")
End If
SRead.Close()
Select Case whatToDo
Case "V"
theFile.Delete()
Case "B"
IO.File.Move("C:\DebitProcessor\2_Verification\" & theFile.Name, "C:\DebitProcessor\3_MasterBatch\" & theFile.Name)
Case "C"
IO.File.Move("C:\DebitProcessor\2_Verification\" & theFile.Name, "C:\DebitProcessor\3_MasterBatch\" & theFile.Name)
End Select
Thanks
-
Nov 14th, 2005, 04:03 AM
#4
Re: Streamreader close error
Where is your "Loop" statement? Can you add the code until it hits that point?
Bill
-
Nov 14th, 2005, 04:40 AM
#5
Thread Starter
Addicted Member
Re: Streamreader close error
Hi,
Ok, this is all the code:
VB Code:
Dim SRead As New IO.StreamReader("C:\Netcash\DebitProcessor\2_Verification\" & theFile.Name)
strLine = SRead.ReadLine()
strLine = SRead.ReadLine()
strLine = SRead.ReadLine()
theProgressCount = 2
Do While Not strLine Is Nothing
LineArray = Split(strLine, """,""", -1)
theProgressCount + 1
For i = 0 To UBound(LineArray)
theFieldValue = Replace(LineArray(i), """", "")
Select Case i
Case 0
If theFieldValue = "##END##" Then
End If
theAccountReferrence = Validation.FReturnString(theFieldValue, 22)
Case 1
theAccountName = Validation.FReturnString(theFieldValue, 49)
Case 2
theBankAccountName = Validation.FReturnString(theFieldValue, 49)
Case 3
theAccountType = Validation.FReturnNumber(theFieldValue, 1)
Case 4
theBranchCode = Validation.FillBranchCode(theFieldValue)
Case 5
theBankAccountNumber = Validation.FReturnNumber(theFieldValue, 16)
Case 6
theContractAmount = theFieldValue / 100
Case 7
theBatchAmount = theFieldValue / 100
Case 8
If Validation.FEmailVerify(theFieldValue) = False Then
theEmail = ""
Else
theEmail = theFieldValue
End If
Case 9
theNameOnCC = Validation.FReturnString(theFieldValue, 49)
Case 10
theNumberOnCC = Validation.FReturnNumber(theFieldValue, 16)
Case 11
theMonthExpires = Validation.FReturnNumber(theFieldValue, 2)
Case 12
theYearExpires = Validation.FReturnNumber(theFieldValue, 4)
Case 13
theCardType = Validation.FReturnNumber(theFieldValue, 1)
Case 14
IsCreditCard = Validation.FReturnNumber(theFieldValue, 1)
Case 15
theExtra1 = theFieldValue
Case 16
theExtra2 = theFieldValue
Case 17
theExtra3 = theFieldValue
End Select
Next
If IsCreditCard = 0 Then
VReturn = 0
VReturn = Validation.CDVValidateAccount(theBankAccountNumber, theBranchCode, theAccountType)
If VReturn <> 0 Then
ErrorDetected = True
Select Case VReturn
Case 0
theErrorText = "OK"
Case 1
theErrorText = "INVALID BRANCH CODE"
Case 2
theErrorText = "INVALID ACCOUNT NO"
Case 3
theErrorText = "INVALID ACCOUNT TYPE"
End Select
'MsgBox(theAccountReferrence & " : " & theAccountType & " : " & theBranchCode & " : " & theBankAccountNumber)
theErrorString = theErrorString & "Acc Ref :" & theAccountReferrence & " Line : " & theProgressCount & " has a CDV Error No : " & VReturn & " - " & theErrorText & vbCrLf
End If
VReturn = 0
Else
Select Case theCardType
Case "1"
theStrCardType = "MasterCard"
Case "2"
theStrCardType = "Visa"
Case "3"
theStrCardType = "AMEX"
Case "4"
theStrCardType = "Diners"
Case Else
theStrCardType = "0"
End Select
If Validation.FIsCreditCard(theStrCardType, theNumberOnCC) = False Then
ErrorDetected = True
theErrorString = theErrorString & "Line : " & theProgressCount & " has an Invalid Credit Card Number : " & vbCrLf
End If
End If
strLine = SRead.ReadLine()
Loop
SRead.Close()
GC.Collect()
If ErrorDetected = True Then
theErrorString = theErrorString & "Please check your documentation to see the explanation for the error codes." & vbCrLf & vbCrLf & "Thank You" & vbCrLf & "Netcash"
Mailer.SendMail(ReplyMail, ReplyMail, "103 CDV Check return from Netcash. ", "Your data has failed the CDV check. Below you will see the records that have failed." & vbCrLf & vbCrLf & theErrorString)
Mailer.SendMail(NetcashSupportMail, NetcashSupportMail, "103 CDV Check return from Netcash. ", "Your data has failed the CDV check. Below you will see the records that have failed." & vbCrLf & vbCrLf & theErrorString)
'Select Case Err.Number
' Case 0 'no error
' 'MsgBox("allok")
' Case Else
' MsgBox("An error occurred: " + Err.Description + " " + Err.Number + " " + Err.HelpContext)
' End
'End Select
Else
Mailer.SendMail(ReplyMail, ReplyMail, "102 CDV Check Complete. Updates and/or Batch queued to follow. ", "Your File has run through the CDV successfully. Please remember that if you have sent us a batch instruction, that it will need to be authorized online. " & vbCrLf & vbCrLf & "Thank You" & vbCrLf & "Netcash")
'Mailer.SendMail(NetcashSupportMail, NetcashSupportMail, "102 CDV Check Complete. Updates and/or Batch queued to follow. ", "Your File has run through the CDV successfully. Please remember that if you have sent us a batch instruction, that it will need to be authorized online. " & vbCrLf & vbCrLf & "Thank You" & vbCrLf & "Netcash")
End If
Select Case whatToDo
Case "V"
'theFile.Delete()
OFile.Delete("C:\Netcash\DebitProcessor\2_Verification\" & theFile.Name)
Case "B"
OFile.Move("C:\Netcash\DebitProcessor\2_Verification\" & theFile.Name, "C:\Netcash\DebitProcessor\3_MasterBatch\" & theFile.Name)
IO.File.Move("C:\Netcash\DebitProcessor\2_Verification\" & theFile.Name, "C:\Netcash\DebitProcessor\3_MasterBatch\" & theFile.Name)
Case "C"
IO.File.Move("C:\Netcash\DebitProcessor\2_Verification\" & theFile.Name, "C:\Netcash\DebitProcessor\3_MasterBatch\" & theFile.Name)
End Select
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|