Ir para conteúdo

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

lezão

Excluir registros de um BD automaticamente!

Recommended Posts

Galera encontrei esse codigo no laboratorio

http://forum.imasters.com.br/topic/182840-excluir-registro-automaticamente-com-a-data-vencida/

 

só q fica dando o seguinte erro

ADODB.Recordset error '800a0e78'

Operation is not allowed when the object is closed.

/site/1.asp, line 108

fiz assim

<!--#include file="includes/Config.asp"-->

<!--#include file="includes/Adovbs.inc"-->

<%

Call AbreBanco

Dim VarAct

VarAct = Request.QueryString("Act")

Dim ConsApagar
Dim ConsApagar_numRows


Set ConsApagar = Server.CreateObject("ADODB.Recordset")
ConsApagar.ActiveConnection = Banco
ConsApagar.Source = "Delete * from Publicidade where vencto < datevalue('"&now()-1&"')"
ConsApagar.CursorType = 0
ConsApagar.CursorLocation = 2
ConsApagar.LockType = 1
ConsApagar.Open()

ConsApagar_numRows = 0

%>
<%
Dim Repeat1__numRows
Dim Repeat1__index

Repeat1__numRows = -1
Repeat1__index = 0
ConsApagar_numRows = ConsApagar_numRows + Repeat1__numRows
%>
<%
Dim MM_paramName 
%>
<%
' *** Go To Record and Move To Record: create strings for maintaining URL and Form parameters

Dim MM_keepNone
Dim MM_keepURL
Dim MM_keepForm
Dim MM_keepBoth

Dim MM_removeList
Dim MM_item
Dim MM_nextItem

' create the list of parameters which should not be maintained
MM_removeList = "&index="
If (MM_paramName <> "") Then
MM_removeList = MM_removeList & "&" & MM_paramName & "="
End If

MM_keepURL=""
MM_keepForm=""
MM_keepBoth=""
MM_keepNone=""

' add the URL parameters to the MM_keepURL string
For Each MM_item In Request.QueryString
MM_nextItem = "&" & MM_item & "="
If (InStr(1,MM_removeList,MM_nextItem,1) = 0) Then
MM_keepURL = MM_keepURL & MM_nextItem & Server.URLencode(Request.QueryString(MM_item))
End If
Next

' add the Form variables to the MM_keepForm string
For Each MM_item In Request.Form
MM_nextItem = "&" & MM_item & "="
If (InStr(1,MM_removeList,MM_nextItem,1) = 0) Then
MM_keepForm = MM_keepForm & MM_nextItem & Server.URLencode(Request.Form(MM_item))
End If
Next

' create the Form + URL string and remove the intial '&' from each of the strings
MM_keepBoth = MM_keepURL & MM_keepForm
If (MM_keepBoth <> "") Then 
MM_keepBoth = Right(MM_keepBoth, Len(MM_keepBoth) - 1)
End If
If (MM_keepURL <> "") Then
MM_keepURL = Right(MM_keepURL, Len(MM_keepURL) - 1)
End If
If (MM_keepForm <> "") Then
MM_keepForm = Right(MM_keepForm, Len(MM_keepForm) - 1)
End If

' a utility function used for adding additional parameters to these strings
Function MM_joinChar(firstItem)
If (firstItem <> "") Then
MM_joinChar = "&"
Else
MM_joinChar = ""
End If
End Function
%>
<body>
<table width="468" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="100"><div align="center" class="style4">Vencimento</div></td>
<td width="338"><div align="center" class="style4">Evento</div></td>
<td width="30"><div align="center" class="style4"></div></td>
</tr>
<tr>
<td colspan="3"><% 
While ((Repeat1__numRows <> 0) AND (NOT ConsApagar.EOF))
%>
<table width="468" border="0" cellspacing="2" cellpadding="2">
<tr>
<td width="100" class="style5"><strong><%=(ConsApagar.Fields.Item("Vencto").Value)%></strong></td>
<td width="338" class="style5 style6"><%=(ConsApagar.Fields.Item("Empresa").Value)%></td>
<td width="30" class="style5"><div align="center"><strong><A HREF="Exibir.asp?<%= Server.HTMLEncode(MM_keepURL) & MM_joinChar(MM_keepURL) & "Cod=" & ConsApagar.Fields.Item("Cod").Value %>">VER</A></strong></div></td>
</tr>
</table>
<% 
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
ConsApagar.MoveNext()
Wend
%><span class="style5"></span></td>
</tr>
</table>
</body>
</html>
<%
ConsApagar.Close()
Set ConsApagar = Nothing
%>

O que eu fiz em um caso mais ou menos parecido foi assim.

 

A cada 24 horas roda uma pagina automaticamente com javascript

 

Segue o código

<script type="application/javascript" language="javascript">
window.setTimeout(function(){
	//document.getElementById("ok").style.display='none'
	document.location.href = 'http://www.dominio.com.br/deletar/deletar.asp'
	//$("#banner").css("display","none");
}, 86400000);
//86400000 = 24horas
//43200000 = 12horas
</script>

Sendo assim de 24 em 24 horas ele roda a pagina deletar.asp.

 

Att;

entaun ele roda apagar tudo ou apenas os registros vencidos?

Compartilhar este post


Link para o post
Compartilhar em outros sites

ele apagará somente os recordsets com now()-1, pegando a data menos 1 dia

Compartilhar este post


Link para o post
Compartilhar em outros sites

e si eu colocar assim

ConsApagar.Source = "Delete * from Publicidade where datavencto < datevalue('"&now()+30&"')"

será q ele vai excluir os q vaun vencer daki 30 trinta????

Compartilhar este post


Link para o post
Compartilhar em outros sites

O que eu fiz em um caso mais ou menos parecido foi assim.

 

A cada 24 horas roda uma pagina automaticamente com javascript

 

Segue o código

<script type="application/javascript" language="javascript">
window.setTimeout(function(){
	//document.getElementById("ok").style.display='none'
	document.location.href = 'http://www.dominio.com.br/deletar/deletar.asp'
	//$("#banner").css("display","none");
}, 86400000);
//86400000 = 24horas
//43200000 = 12horas
</script>

Sendo assim de 24 em 24 horas ele roda a pagina deletar.asp.

 

Att;

o gilberto eu conseguiria fazer o mesmo sistema de tempo so que para email?eu cheguei a colocar em outro topico meu server ate tem agendador mas tem que pagar a mais por isso ae fica tenso. preciso mandar um email toda sexta feira para as mesmas pessoas com o mesmo texto a parte do email sei fazer so nao sei como fazer o agendamento

Compartilhar este post


Link para o post
Compartilhar em outros sites

Sim, eu tenho um agendamento de 24 horas de envio de e-mail. Ou seja, todo dia de manhã volta por volta de 07:40.

 

Att;

mas entao gilberto como faria para enviar toda semana?e no meu caso so poderia upar e executar a pagina na proxima sexta feira correto? para pode contar mais 7 dias.

estive olhando o seu codigo

//86400000 = 24horas

//43200000 = 12horas

 

essa conta é em segundo correto?

logo para executar de 7 em 7 dias usuaria:

604800000

 

 

?????

Compartilhar este post


Link para o post
Compartilhar em outros sites

Sim,

 

Seria 604800000 e a pagina tem que esta aberta direto para o comando ser executado.

 

Att;

Opa essa parte nao entendi, a pagina tem que estar aberta? qual pagina vc diz? a deste codigo ela tem que ficar aberta a semana inteira no meu caso?

Compartilhar este post


Link para o post
Compartilhar em outros sites

A pagina que vai o código

<script type="application/javascript" language="javascript">
window.setTimeout(function(){
    //document.getElementById("ok").style.display='none'
    document.location.href = 'http://www.dominio.com.br/deletar/deletar.asp'
    //$("#banner").css("display","none");
}, 86400000);
//86400000 = 24horas
//43200000 = 12horas

</script> 

 

tem que ficar aberta a semana inteira sim...

 

Como fazer para o sistema funcionar com a pagina fechada eu não sei fazer ainda.

 

Att;

Compartilhar este post


Link para o post
Compartilhar em outros sites

Vc pode fazer um agendamento no seu host

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.