后台数据库成功后,将读取的dbf文件删除。现在的问题是我读取了dbf并提交之后将打开的
recordset和Connection都关闭掉了,但是当我运行kill命令时系统提示无权限进行此操作,
于是我尝试用vfp打开刚刚访问的dbf系统提示表已打开。
请教各位兄台,我该如何彻底关闭这个已打开的dbf文件呢?
类代码如下
Private classcnn As New Connection
Public Function creatlink(ByVal fflj As String) As Boolean
On Error GoTo ErrorHandler
Dim classlink As String
classlink = "provider=msdasql;DRIVER=Microsoft Visual FoxPro Driver;UID=;Deleted=yes;Null=no;"
classlink = classlink + "SourceType=DBF;SourceDB=" & fflj & ";"
classcnn.Open classlink
creatlink = True
Exit Function ' 退出程序,以避免进入错误处理程序。
ErrorHandler: ' 错误处理程序。
msg = MsgBox("打开连接失败!", 0, "类错误!")
Set classcnnk = Nothing
creatlink = False
End Function
Public Function readdbf(ByVal calssfile As String) As Recordset
On Error GoTo ErrorHandler
Dim ffile As String
Dim calssrs As Recordset
ffile = calssfile
Set calssrs = classcnn.Execute("select * from " & ffile)
set readdbf = calssrs
Exit Function
ErrorHandler: ' 错误处理程序。
msg = MsgBox("打开表" & ffile & "失败!" & Err.Description, 0, "类错误!")
Set classcnnk = Nothing
End Function
Public Function endcls()
If classcnn.State = 1 Then
classcnn.Close
End If
Set classcnn = Nothing
End Function
18 个解决方案
#1
没有看到你关闭recordset的语句,只看到关闭connection的语句,你把中间的那段代码改一下再试试:
Public Function readdbf(ByVal calssfile As String) As Recordset
On Error GoTo ErrorHandler
Dim ffile As String
Dim calssrs As Recordset
ffile = calssfile
Set calssrs = classcnn.Execute("select * from " & ffile)
set readdbf = calssrs.Clone '<---------------------------------这句是改过的
'加上下面这两句,关闭记录集,并释放对象
calssrs.Close
Set calssrs=Noothing
Exit Function
ErrorHandler: ' 错误处理程序。
msg = MsgBox("打开表" & ffile & "失败!" & Err.Description, 0, "类错误!")
Set classcnnk = Nothing
End Function
Public Function readdbf(ByVal calssfile As String) As Recordset
On Error GoTo ErrorHandler
Dim ffile As String
Dim calssrs As Recordset
ffile = calssfile
Set calssrs = classcnn.Execute("select * from " & ffile)
set readdbf = calssrs.Clone '<---------------------------------这句是改过的
'加上下面这两句,关闭记录集,并释放对象
calssrs.Close
Set calssrs=Noothing
Exit Function
ErrorHandler: ' 错误处理程序。
msg = MsgBox("打开表" & ffile & "失败!" & Err.Description, 0, "类错误!")
Set classcnnk = Nothing
End Function
#2
楼上的兄弟!你修改过的这句语句执行不过去哦
系统提示 “当前记录集不支持书签!这可能是程序选定的游标类型限制的”
我的程序里是先调用
creatlink方法建立连接
然后使用readdbf方法读出并返回dbf表里的记录
然后提交到后台
提交完毕后
执行endcls
关闭连接
系统提示 “当前记录集不支持书签!这可能是程序选定的游标类型限制的”
我的程序里是先调用
creatlink方法建立连接
然后使用readdbf方法读出并返回dbf表里的记录
然后提交到后台
提交完毕后
执行endcls
关闭连接
#3
你要记得删除文件前关闭连接及记录集就可以了,检查一下吧。另外,你的记录集引用很不好,极有可能导致无效引用,因为你原始的记录集对象是个局部变量。
#4
系统提示 “当前记录集不支持书签!这可能是程序选定的游标类型限制的”
-------------------------------------------------------------------------
那是因为没有设置客户端游标引起的,加上一句就好了:
Private classcnn As New Connection
Public Function creatlink(ByVal fflj As String) As Boolean
On Error GoTo ErrorHandler
Dim classlink As String
classlink = "provider=msdasql;DRIVER=Microsoft Visual FoxPro Driver;UID=;Deleted=yes;Null=no;"
classlink = classlink + "SourceType=DBF;SourceDB=" & fflj & ";"
classcnn.CursorLocation=adUseClient '设置客户端游标
classcnn.Open classlink
......
-------------------------------------------------------------------------
那是因为没有设置客户端游标引起的,加上一句就好了:
Private classcnn As New Connection
Public Function creatlink(ByVal fflj As String) As Boolean
On Error GoTo ErrorHandler
Dim classlink As String
classlink = "provider=msdasql;DRIVER=Microsoft Visual FoxPro Driver;UID=;Deleted=yes;Null=no;"
classlink = classlink + "SourceType=DBF;SourceDB=" & fflj & ";"
classcnn.CursorLocation=adUseClient '设置客户端游标
classcnn.Open classlink
......
#5
自己顶
#6
我把这个程序改成了个测试函数
Public Function test() As Boolean
Dim classcnn As New Connection
Dim calssrs As Recordset
Dim classlink As String
classlink = "provider=msdasql;DRIVER=Microsoft Visual FoxPro Driver;UID=;Deleted=yes;Null=no;"
classlink = classlink + "SourceType=DBF;SourceDB=K:\pharmail\;"
classcnn.CursorLocation = adUseClient
classcnn.Open classlink
Set calssrs = classcnn.Execute("select * from AACF012601.DBF")
calssrs.Close
Set calssrs = Nothing
classcnn.Close
Set classcnn = Nothing
KillFile "k:\pharmail\AACF012601.DBF"
End Function
KillFile "k:\pharmail\AACF012601.DBF"仍然报错
还是提示没权限
Public Function test() As Boolean
Dim classcnn As New Connection
Dim calssrs As Recordset
Dim classlink As String
classlink = "provider=msdasql;DRIVER=Microsoft Visual FoxPro Driver;UID=;Deleted=yes;Null=no;"
classlink = classlink + "SourceType=DBF;SourceDB=K:\pharmail\;"
classcnn.CursorLocation = adUseClient
classcnn.Open classlink
Set calssrs = classcnn.Execute("select * from AACF012601.DBF")
calssrs.Close
Set calssrs = Nothing
classcnn.Close
Set classcnn = Nothing
KillFile "k:\pharmail\AACF012601.DBF"
End Function
KillFile "k:\pharmail\AACF012601.DBF"仍然报错
还是提示没权限
#7
各位仁兄,救命啊!
#8
试试把语句改一下:
KillFile "k:\pharmail\AACF012601.DBF"
改为:
CreateObject("Scripting.FileSystemObject").DeleteFile "k:\pharmail\AACF012601.DBF", True
KillFile "k:\pharmail\AACF012601.DBF"
改为:
CreateObject("Scripting.FileSystemObject").DeleteFile "k:\pharmail\AACF012601.DBF", True
#9
还是提示拒绝的权限啊。。。晕
#10
faysky2兄!我找到了出问题的原因但无法解决
我做了个测试函数
Public Sub main()
'Dim strcnn As String
Set cnn = New ADODB.Connection
strcnn = "Driver={SQL Server};Server=backserver;DataBase=chain;UID=sa;PWD="
cnn.Open strcnn
cnn.CommandTimeout = 0
setting
cnn.Close
Set cnn = Nothing '/*关闭cnn连接以后就可以关闭打开的dbf表了*/
test
end sub
Public Function test() As Boolean
Dim classcnn As New ADODB.Connection
Dim calssrs As New Recordset
Dim classlink As String
Set classcnn = New ADODB.Connection
classlink = "provider=msdasql;DRIVER=Microsoft Visual FoxPro Driver;UID=;Deleted=yes;Null=no;"
classlink = classlink + "SourceType=DBF;SourceDB=K:\pharmail\;"
classcnn.CursorLocation = adUseClient
classcnn.Open classlink
Set calssrs = New Recordset
Set calssrs = classcnn.Execute("select * from AAIF091301.DBF")
calssrs.Close
Set calssrs = Nothing
classcnn.Close
Set classcnn = Nothing
CreateObject("Scripting.FileSystemObject").DeleteFile "k:\pharmail\AAIF091301.DBF", True
End Function
一但我的对sqlserver的连接打开了(cnn)
被打开的dbf表就没办法关闭,不能被删除
如果我关闭了sqlserver的连接打开的dbf表就可以被顺利关闭并删除
这是什么问题呢?
我做了个测试函数
Public Sub main()
'Dim strcnn As String
Set cnn = New ADODB.Connection
strcnn = "Driver={SQL Server};Server=backserver;DataBase=chain;UID=sa;PWD="
cnn.Open strcnn
cnn.CommandTimeout = 0
setting
cnn.Close
Set cnn = Nothing '/*关闭cnn连接以后就可以关闭打开的dbf表了*/
test
end sub
Public Function test() As Boolean
Dim classcnn As New ADODB.Connection
Dim calssrs As New Recordset
Dim classlink As String
Set classcnn = New ADODB.Connection
classlink = "provider=msdasql;DRIVER=Microsoft Visual FoxPro Driver;UID=;Deleted=yes;Null=no;"
classlink = classlink + "SourceType=DBF;SourceDB=K:\pharmail\;"
classcnn.CursorLocation = adUseClient
classcnn.Open classlink
Set calssrs = New Recordset
Set calssrs = classcnn.Execute("select * from AAIF091301.DBF")
calssrs.Close
Set calssrs = Nothing
classcnn.Close
Set classcnn = Nothing
CreateObject("Scripting.FileSystemObject").DeleteFile "k:\pharmail\AAIF091301.DBF", True
End Function
一但我的对sqlserver的连接打开了(cnn)
被打开的dbf表就没办法关闭,不能被删除
如果我关闭了sqlserver的连接打开的dbf表就可以被顺利关闭并删除
这是什么问题呢?
#11
你一个空表将其覆盖掉就行了嘛,这样也不用删除,数据也没了.
这可能是由于,你还是由于没有NOTHING掉,所以还是无法关闭掉的,你把记录集与连接都关闭掉,且都NOTHING掉,看看这样行不行
这可能是由于,你还是由于没有NOTHING掉,所以还是无法关闭掉的,你把记录集与连接都关闭掉,且都NOTHING掉,看看这样行不行
#12
两个连接都关掉,就可以删除,但是这两个连接有冲突吗?
#13
求教各位高人!帮下忙啊!
没理由两个不同的连接会互相影响吧
没理由两个不同的连接会互相影响吧
#14
sql的连接是用cnn,是不是你用cnn操作了dbf文件呢,比如 读取dbf的数据,插入到sql里??
#15
恩,我现在做的测试函数没有做插入的操作了啊!
faysky2兄!
只是很简单的
先打开sqlserver的连接
然后再打开dbf的连接,然后用dbf的连接执行了个打开表sql语句并返回一个recordset
然后再关闭dbf连接和被打开的recordset
再删除被打开过的dbf文件
中间没有涉及到任何想关的cnn的操作啊
这种情况下,我不关闭cnn并且把cnn设置为nothing
被打开过的哪个表还是不能被删除。。。。。。
我已经完全被搞晕了。。。。
faysky2兄!
只是很简单的
先打开sqlserver的连接
然后再打开dbf的连接,然后用dbf的连接执行了个打开表sql语句并返回一个recordset
然后再关闭dbf连接和被打开的recordset
再删除被打开过的dbf文件
中间没有涉及到任何想关的cnn的操作啊
这种情况下,我不关闭cnn并且把cnn设置为nothing
被打开过的哪个表还是不能被删除。。。。。。
我已经完全被搞晕了。。。。
#16
自己顶下,希望这个疑问能有解答谢谢大家
#17
很奇怪,看起来没什么问题哦,看到你上面的测试代码中,有一个 setting ,好象是函数,它有没有打开pdf文件?
没有测试环境,不能给你测试了
没有测试环境,不能给你测试了
#18
Public Sub setting()
Dim path As String * 255
Dim i As Integer
i = GetCurrentDirectoryA(Len(path), path) '获取当前路径
Currentpath = getpath(path)
MsgBox (Currentpath)
filepath = "k:\pharmail\"
backpath = "d:\movefile\"
runstime = Time
End Sub
是个环境设置的过程
用来设置基本的环境信息,默认路径,文件存放路径,文件接收路径,系统运行的初时时间
会不会是我的vb6没打补丁,有bug?
Dim path As String * 255
Dim i As Integer
i = GetCurrentDirectoryA(Len(path), path) '获取当前路径
Currentpath = getpath(path)
MsgBox (Currentpath)
filepath = "k:\pharmail\"
backpath = "d:\movefile\"
runstime = Time
End Sub
是个环境设置的过程
用来设置基本的环境信息,默认路径,文件存放路径,文件接收路径,系统运行的初时时间
会不会是我的vb6没打补丁,有bug?
#1
没有看到你关闭recordset的语句,只看到关闭connection的语句,你把中间的那段代码改一下再试试:
Public Function readdbf(ByVal calssfile As String) As Recordset
On Error GoTo ErrorHandler
Dim ffile As String
Dim calssrs As Recordset
ffile = calssfile
Set calssrs = classcnn.Execute("select * from " & ffile)
set readdbf = calssrs.Clone '<---------------------------------这句是改过的
'加上下面这两句,关闭记录集,并释放对象
calssrs.Close
Set calssrs=Noothing
Exit Function
ErrorHandler: ' 错误处理程序。
msg = MsgBox("打开表" & ffile & "失败!" & Err.Description, 0, "类错误!")
Set classcnnk = Nothing
End Function
Public Function readdbf(ByVal calssfile As String) As Recordset
On Error GoTo ErrorHandler
Dim ffile As String
Dim calssrs As Recordset
ffile = calssfile
Set calssrs = classcnn.Execute("select * from " & ffile)
set readdbf = calssrs.Clone '<---------------------------------这句是改过的
'加上下面这两句,关闭记录集,并释放对象
calssrs.Close
Set calssrs=Noothing
Exit Function
ErrorHandler: ' 错误处理程序。
msg = MsgBox("打开表" & ffile & "失败!" & Err.Description, 0, "类错误!")
Set classcnnk = Nothing
End Function
#2
楼上的兄弟!你修改过的这句语句执行不过去哦
系统提示 “当前记录集不支持书签!这可能是程序选定的游标类型限制的”
我的程序里是先调用
creatlink方法建立连接
然后使用readdbf方法读出并返回dbf表里的记录
然后提交到后台
提交完毕后
执行endcls
关闭连接
系统提示 “当前记录集不支持书签!这可能是程序选定的游标类型限制的”
我的程序里是先调用
creatlink方法建立连接
然后使用readdbf方法读出并返回dbf表里的记录
然后提交到后台
提交完毕后
执行endcls
关闭连接
#3
你要记得删除文件前关闭连接及记录集就可以了,检查一下吧。另外,你的记录集引用很不好,极有可能导致无效引用,因为你原始的记录集对象是个局部变量。
#4
系统提示 “当前记录集不支持书签!这可能是程序选定的游标类型限制的”
-------------------------------------------------------------------------
那是因为没有设置客户端游标引起的,加上一句就好了:
Private classcnn As New Connection
Public Function creatlink(ByVal fflj As String) As Boolean
On Error GoTo ErrorHandler
Dim classlink As String
classlink = "provider=msdasql;DRIVER=Microsoft Visual FoxPro Driver;UID=;Deleted=yes;Null=no;"
classlink = classlink + "SourceType=DBF;SourceDB=" & fflj & ";"
classcnn.CursorLocation=adUseClient '设置客户端游标
classcnn.Open classlink
......
-------------------------------------------------------------------------
那是因为没有设置客户端游标引起的,加上一句就好了:
Private classcnn As New Connection
Public Function creatlink(ByVal fflj As String) As Boolean
On Error GoTo ErrorHandler
Dim classlink As String
classlink = "provider=msdasql;DRIVER=Microsoft Visual FoxPro Driver;UID=;Deleted=yes;Null=no;"
classlink = classlink + "SourceType=DBF;SourceDB=" & fflj & ";"
classcnn.CursorLocation=adUseClient '设置客户端游标
classcnn.Open classlink
......
#5
自己顶
#6
我把这个程序改成了个测试函数
Public Function test() As Boolean
Dim classcnn As New Connection
Dim calssrs As Recordset
Dim classlink As String
classlink = "provider=msdasql;DRIVER=Microsoft Visual FoxPro Driver;UID=;Deleted=yes;Null=no;"
classlink = classlink + "SourceType=DBF;SourceDB=K:\pharmail\;"
classcnn.CursorLocation = adUseClient
classcnn.Open classlink
Set calssrs = classcnn.Execute("select * from AACF012601.DBF")
calssrs.Close
Set calssrs = Nothing
classcnn.Close
Set classcnn = Nothing
KillFile "k:\pharmail\AACF012601.DBF"
End Function
KillFile "k:\pharmail\AACF012601.DBF"仍然报错
还是提示没权限
Public Function test() As Boolean
Dim classcnn As New Connection
Dim calssrs As Recordset
Dim classlink As String
classlink = "provider=msdasql;DRIVER=Microsoft Visual FoxPro Driver;UID=;Deleted=yes;Null=no;"
classlink = classlink + "SourceType=DBF;SourceDB=K:\pharmail\;"
classcnn.CursorLocation = adUseClient
classcnn.Open classlink
Set calssrs = classcnn.Execute("select * from AACF012601.DBF")
calssrs.Close
Set calssrs = Nothing
classcnn.Close
Set classcnn = Nothing
KillFile "k:\pharmail\AACF012601.DBF"
End Function
KillFile "k:\pharmail\AACF012601.DBF"仍然报错
还是提示没权限
#7
各位仁兄,救命啊!
#8
试试把语句改一下:
KillFile "k:\pharmail\AACF012601.DBF"
改为:
CreateObject("Scripting.FileSystemObject").DeleteFile "k:\pharmail\AACF012601.DBF", True
KillFile "k:\pharmail\AACF012601.DBF"
改为:
CreateObject("Scripting.FileSystemObject").DeleteFile "k:\pharmail\AACF012601.DBF", True
#9
还是提示拒绝的权限啊。。。晕
#10
faysky2兄!我找到了出问题的原因但无法解决
我做了个测试函数
Public Sub main()
'Dim strcnn As String
Set cnn = New ADODB.Connection
strcnn = "Driver={SQL Server};Server=backserver;DataBase=chain;UID=sa;PWD="
cnn.Open strcnn
cnn.CommandTimeout = 0
setting
cnn.Close
Set cnn = Nothing '/*关闭cnn连接以后就可以关闭打开的dbf表了*/
test
end sub
Public Function test() As Boolean
Dim classcnn As New ADODB.Connection
Dim calssrs As New Recordset
Dim classlink As String
Set classcnn = New ADODB.Connection
classlink = "provider=msdasql;DRIVER=Microsoft Visual FoxPro Driver;UID=;Deleted=yes;Null=no;"
classlink = classlink + "SourceType=DBF;SourceDB=K:\pharmail\;"
classcnn.CursorLocation = adUseClient
classcnn.Open classlink
Set calssrs = New Recordset
Set calssrs = classcnn.Execute("select * from AAIF091301.DBF")
calssrs.Close
Set calssrs = Nothing
classcnn.Close
Set classcnn = Nothing
CreateObject("Scripting.FileSystemObject").DeleteFile "k:\pharmail\AAIF091301.DBF", True
End Function
一但我的对sqlserver的连接打开了(cnn)
被打开的dbf表就没办法关闭,不能被删除
如果我关闭了sqlserver的连接打开的dbf表就可以被顺利关闭并删除
这是什么问题呢?
我做了个测试函数
Public Sub main()
'Dim strcnn As String
Set cnn = New ADODB.Connection
strcnn = "Driver={SQL Server};Server=backserver;DataBase=chain;UID=sa;PWD="
cnn.Open strcnn
cnn.CommandTimeout = 0
setting
cnn.Close
Set cnn = Nothing '/*关闭cnn连接以后就可以关闭打开的dbf表了*/
test
end sub
Public Function test() As Boolean
Dim classcnn As New ADODB.Connection
Dim calssrs As New Recordset
Dim classlink As String
Set classcnn = New ADODB.Connection
classlink = "provider=msdasql;DRIVER=Microsoft Visual FoxPro Driver;UID=;Deleted=yes;Null=no;"
classlink = classlink + "SourceType=DBF;SourceDB=K:\pharmail\;"
classcnn.CursorLocation = adUseClient
classcnn.Open classlink
Set calssrs = New Recordset
Set calssrs = classcnn.Execute("select * from AAIF091301.DBF")
calssrs.Close
Set calssrs = Nothing
classcnn.Close
Set classcnn = Nothing
CreateObject("Scripting.FileSystemObject").DeleteFile "k:\pharmail\AAIF091301.DBF", True
End Function
一但我的对sqlserver的连接打开了(cnn)
被打开的dbf表就没办法关闭,不能被删除
如果我关闭了sqlserver的连接打开的dbf表就可以被顺利关闭并删除
这是什么问题呢?
#11
你一个空表将其覆盖掉就行了嘛,这样也不用删除,数据也没了.
这可能是由于,你还是由于没有NOTHING掉,所以还是无法关闭掉的,你把记录集与连接都关闭掉,且都NOTHING掉,看看这样行不行
这可能是由于,你还是由于没有NOTHING掉,所以还是无法关闭掉的,你把记录集与连接都关闭掉,且都NOTHING掉,看看这样行不行
#12
两个连接都关掉,就可以删除,但是这两个连接有冲突吗?
#13
求教各位高人!帮下忙啊!
没理由两个不同的连接会互相影响吧
没理由两个不同的连接会互相影响吧
#14
sql的连接是用cnn,是不是你用cnn操作了dbf文件呢,比如 读取dbf的数据,插入到sql里??
#15
恩,我现在做的测试函数没有做插入的操作了啊!
faysky2兄!
只是很简单的
先打开sqlserver的连接
然后再打开dbf的连接,然后用dbf的连接执行了个打开表sql语句并返回一个recordset
然后再关闭dbf连接和被打开的recordset
再删除被打开过的dbf文件
中间没有涉及到任何想关的cnn的操作啊
这种情况下,我不关闭cnn并且把cnn设置为nothing
被打开过的哪个表还是不能被删除。。。。。。
我已经完全被搞晕了。。。。
faysky2兄!
只是很简单的
先打开sqlserver的连接
然后再打开dbf的连接,然后用dbf的连接执行了个打开表sql语句并返回一个recordset
然后再关闭dbf连接和被打开的recordset
再删除被打开过的dbf文件
中间没有涉及到任何想关的cnn的操作啊
这种情况下,我不关闭cnn并且把cnn设置为nothing
被打开过的哪个表还是不能被删除。。。。。。
我已经完全被搞晕了。。。。
#16
自己顶下,希望这个疑问能有解答谢谢大家
#17
很奇怪,看起来没什么问题哦,看到你上面的测试代码中,有一个 setting ,好象是函数,它有没有打开pdf文件?
没有测试环境,不能给你测试了
没有测试环境,不能给你测试了
#18
Public Sub setting()
Dim path As String * 255
Dim i As Integer
i = GetCurrentDirectoryA(Len(path), path) '获取当前路径
Currentpath = getpath(path)
MsgBox (Currentpath)
filepath = "k:\pharmail\"
backpath = "d:\movefile\"
runstime = Time
End Sub
是个环境设置的过程
用来设置基本的环境信息,默认路径,文件存放路径,文件接收路径,系统运行的初时时间
会不会是我的vb6没打补丁,有bug?
Dim path As String * 255
Dim i As Integer
i = GetCurrentDirectoryA(Len(path), path) '获取当前路径
Currentpath = getpath(path)
MsgBox (Currentpath)
filepath = "k:\pharmail\"
backpath = "d:\movefile\"
runstime = Time
End Sub
是个环境设置的过程
用来设置基本的环境信息,默认路径,文件存放路径,文件接收路径,系统运行的初时时间
会不会是我的vb6没打补丁,有bug?