我在页面上有一个循环来更新一个需要15-20秒才能完成的访问数据库。我最多每月运行一次,但我注意到每次运行它时,网站(IIS 6)都会停止提供页面。
循环结束后,页面再次开始打开。
这是我的代码:
For each Email in Emails
if Trim(Email) <> "" then
' execute the update
Set MM_editCmd = Server.CreateObject("ADODB.Command")
MM_editCmd.ActiveConnection = MM_Customers_STRING
MM_editCmd.CommandText = "UPDATE Customers SET MailingListUpdates=False WHERE Email='" & Trim(Email) & "'"
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close
Response.Write "Email address " & Email & " successfully removed from the mailing list.<br>"
end if
Next
我能做些什么来避免这种情况吗?
上次更新的电子邮件大约有700条记录。
答案 0 :(得分:2)
您可能正在耗尽连接池中的所有可用连接。试试这个:
Set MM_editCmd = Server.CreateObject("ADODB.Command")
MM_editCmd.ActiveConnection = MM_Customers_STRING
For each Email in Emails
if Trim(Email) <> "" then
' execute the update
MM_editCmd.CommandText = "UPDATE Customers SET MailingListUpdates=False WHERE Email='" & Trim(Email) & "'"
MM_editCmd.Execute
Response.Write "Email address " & Email & " successfully removed from the mailing list.<br>"
end if
Next
MM_editCmd.ActiveConnection.Close
同样作为更长期的事情尝试升级到SQL Server Express
答案 1 :(得分:2)
试试这个: -
Dim con : Set con = Server.CreateObject("ADODB.Connection")
Dim cmd : Set cmd = Server.CreateObject("ADODB.Command")
con.Open MM_Customers_STRING
Set cmd.ActiveConnection = con
cmd.CommandType = 1 // adCmdText (note SO not good at detecting VB comment)
cmd.CommandText = "UPDATE Customers SET MailingListUpdates=False WHERE Email=?"
Dim param : Set param = cmd.CreateParameter("email", 200, 1, 50) // adVarChar, adParamInput, size: 50
cmd.Parameters.Append param
Dim Email
For Each Email in Emails
Email = Trim(Email)
If Email <> "" Then
param.value = Email
cmd.Execute
End If
Next
con.Close
电子邮件字段的索引会很好。
答案 2 :(得分:1)
我建议创建/删除Command并设置出循环并使用绑定变量(通过Parameters集合)。
答案 3 :(得分:0)
“电子邮件”系列的来源是什么?如果它来自您的数据库,那么通过将其保留在那里并加入其中而不是以编程方式检索和迭代,您将获得更好的性能。另一项改进是仅在必要时执行更新 - 即,MailingListUpdates属性尚未为假。