我看到我用了几年的FTP模块出现了一个奇怪的现象。
任务:
将访问表导出为XLS
将XLS FTP到我的FTP站点
启动存储过程以将XLS插入SQL表
删除FTP文件
问题:最近SP正在返回" 0" (失败)当功能快速连续运行时(即1-2秒内)。我的DBA将错误报告为" 7303"这似乎暗示SP无法获取XLS文件,因为它已锁定OPEN(?)
如果我在运行SP之前在FTP完成后放置了5秒的任意WAIT,那么似乎没问题。
问题:有没有办法强制文件尽快解锁/关闭?
这是FTP功能(不是我的):
Sub myFTP(Filename As String)
Dim INet As Long
Dim INetConn As Long
Dim hostFile As String
Dim localFile As String
Dim Password As String
Dim RetVal As Long
Dim serverName As String
Dim Success As Long
Dim Username As String
Dim strPath As String
Dim strMsg As String
Dim intReply As Integer
Const BINARY_TRANSFER = 2
serverName = "<my ftp address>"
Username = "<my username>"
Password = "<my password>"
strPath = Left(CurrentDb.NAME, InStrRev(CurrentDb.NAME, "\"))
localFile = strPath & Filename
hostFile = Mid(Filename, 1, Len(Filename) - 4) + "upload"
RetVal = False
INet = InternetOpen("MyFTP Control", 1&, vbNullString, vbNullString, 0&)
If INet > 0 Then
INetConn = InternetConnect(INet, serverName, 0&, Username, Password, 1&, 0&, 0&)
If INetConn > 0 Then
Success = FtpPutFile(INetConn, localFile, hostFile, BINARY_TRANSFER, 0&)
RetVal = InternetCloseHandle(INetConn)
End If
RetVal = InternetCloseHandle(INet)
End If
If Success <> 0 Then
'msgbox "FTP Upload Completed"
Else
MsgBox "FTP function failed"
End If
err_Handler_Exit:
Exit Sub
err_Handler:
errMessage Err.Number, Err.Description
Status "[FTP] - There was an FTP error - process stopped.", "Orange"
Resume err_Handler_Exit
End Sub