0

当 SQL 代理在 SQL Server 2005 中作为作业的一部分运行以下每日脚本时,它似乎不会执行最后一行set fso = nothing,并且对象永远不会从内存中删除,从而导致作业在一个月左右后失败。

是否有任何原因导致 SQL 代理似乎不会执行最后一行代码?

dim fso

set fso = CreateObject("Scripting.FileSystemObject")

If fso.FileExists("E:\Foo.mdb") Then
    fso.DeleteFile "E:\Foo.mdb", True
End If

fso.CopyFile "E:\Foo.temp.mdb", "E:\Foo.mdb", True 

set fso = nothing
4

1 回答 1

1

Firstly, you should be applying patches monthly when they come out, hence rebooting monthly.

The days when people proudly measured uptime in years are gone due to the unfortunately all-too-necessary patch cycle. If you genuinely need 24/7/365 access (hint: unlikely) you need a high-availability setup with clustering or replication.

Secondly, I don't think your diagnosis is correct. All objects should be released when the VBScript engine object is destroyed, regardless of whether you released them explicitly. So do you think the FSO is being held in memory? How have you confirmed this?

You could in principle use sysinternals Process Explorer check that the associated DLL is unloaded by the SQL server agent process, which will happen usually within a few minutes of the last object being destroyed.

于 2013-07-05T09:32:00.253 回答