Z
Zachariah
I've created a Windows Service application that creates a
table in an Access database from the information in a text
file, everytime a new textfile shows up in a certain
directory. It functions but I notice that a .ldb file
(Microsoft Access Record-Locking Information) file remains
after the process and it only goes away when the service
is stopped. Why does this happen if I'm closing my
recordset and closing my connection? Here's the code:
Public Sub FileSystemWatcher1_Changed(ByVal sender As _
System.Object, ByVal e As _
System.IO.FileSystemEventArgs) Handles IRWatcher.Created
Dim stTrunc As String
Dim stInPath As String
Dim stOutPath As String
Dim fs
Dim fIn
Dim CnxnEDI As ADODB.Connection
Dim strCnxn As String
Dim strSQL As String
Dim rstEDI As ADODB.Recordset
Dim strLine As String
Dim strField1 As String
Dim strField2 As String
stTrunc = Microsoft.VisualBasic.Left(e.Name, _
(Len(e.Name) - 4))
stInPath = e.FullPath
fs = CreateObject("Scripting.FileSystemObject")
fIn = fs.OpenTextFile(stInPath)
CnxnEDI = New ADODB.Connection
strCnxn = "Provider=Microsoft.JET.OLEDB.4.0; _
Data Source=C:\test_be.mdb"
CnxnEDI.Open(strCnxn)
strSQL = "CREATE TABLE " & stTrunc & " _
(Field1 varchar(8), Field2 text)"
CnxnEDI.Execute(strSQL)
rstEDI = New ADODB.Recordset
strSQL = stTrunc
rstEDI.Open(strSQL, strCnxn, adOpenDynamic, _
adLockPessimistic)
Do While fIn.AtEndOfStream <> True
strLine = fIn.readline
strField1 = Mid(strLine, 1, 8)
strField2 = Trim(Mid(strLine, 10))
With rstEDI
If rstEDI.RecordCount > 0 Then
rstEDI.MoveLast()
rstEDI.AddNew()
rstEDI("Field1").Value = strField1
rstEDI("Field2").Value = strField2
rstEDI.Update()
Else
rstEDI.AddNew()
rstEDI("Field1").Value = strField1
rstEDI("Field2").Value = strField2
rstEDI.Update()
End If
End With
Loop
fIn.Close()
fs = Nothing
rstEDI.Close()
rstEDI = Nothing
CnxnEDI.Close()
CnxnEDI = Nothing
End Sub
table in an Access database from the information in a text
file, everytime a new textfile shows up in a certain
directory. It functions but I notice that a .ldb file
(Microsoft Access Record-Locking Information) file remains
after the process and it only goes away when the service
is stopped. Why does this happen if I'm closing my
recordset and closing my connection? Here's the code:
Public Sub FileSystemWatcher1_Changed(ByVal sender As _
System.Object, ByVal e As _
System.IO.FileSystemEventArgs) Handles IRWatcher.Created
Dim stTrunc As String
Dim stInPath As String
Dim stOutPath As String
Dim fs
Dim fIn
Dim CnxnEDI As ADODB.Connection
Dim strCnxn As String
Dim strSQL As String
Dim rstEDI As ADODB.Recordset
Dim strLine As String
Dim strField1 As String
Dim strField2 As String
stTrunc = Microsoft.VisualBasic.Left(e.Name, _
(Len(e.Name) - 4))
stInPath = e.FullPath
fs = CreateObject("Scripting.FileSystemObject")
fIn = fs.OpenTextFile(stInPath)
CnxnEDI = New ADODB.Connection
strCnxn = "Provider=Microsoft.JET.OLEDB.4.0; _
Data Source=C:\test_be.mdb"
CnxnEDI.Open(strCnxn)
strSQL = "CREATE TABLE " & stTrunc & " _
(Field1 varchar(8), Field2 text)"
CnxnEDI.Execute(strSQL)
rstEDI = New ADODB.Recordset
strSQL = stTrunc
rstEDI.Open(strSQL, strCnxn, adOpenDynamic, _
adLockPessimistic)
Do While fIn.AtEndOfStream <> True
strLine = fIn.readline
strField1 = Mid(strLine, 1, 8)
strField2 = Trim(Mid(strLine, 10))
With rstEDI
If rstEDI.RecordCount > 0 Then
rstEDI.MoveLast()
rstEDI.AddNew()
rstEDI("Field1").Value = strField1
rstEDI("Field2").Value = strField2
rstEDI.Update()
Else
rstEDI.AddNew()
rstEDI("Field1").Value = strField1
rstEDI("Field2").Value = strField2
rstEDI.Update()
End If
End With
Loop
fIn.Close()
fs = Nothing
rstEDI.Close()
rstEDI = Nothing
CnxnEDI.Close()
CnxnEDI = Nothing
End Sub