Showing posts with label old. Show all posts
Showing posts with label old. Show all posts

Thursday, March 22, 2012

30 Day Old Delete

I have a database of posts which i want to delete after 30days of being on the site, my code so far gets all the data out of the table and then if their is more than 0 rows it loops within the tblTable and finds all the posts made within the last 30days and deletes them, my problem is how do I get it to work out 30days ago, for 30days time, its just " DateTime.Now.AddDays(30);" but i cant seem to do something as simple for back in time, heres my code :


private void DeleteOldStuff()
{
string strSQL = "SELECT * FROM ForumPosts";
SqlConnection Connection = new SqlConnection(ConfigurationManager.ConnectionStrings["BlinkConnectionString"].ConnectionString);
Connection.Open();
SqlCommand comm = new SqlCommand(strSQL, Connection);
SqlDataAdapter da = new SqlDataAdapter(comm);
tblData = new DataTable();
da.Fill(tblData);
Connection.Close();
if (tblData.Rows.Count > 0)
{
for (int i = 0; i < tblData.Rows.Count; i++)
{
DataRow dr = tblData.Rows[i];
if ("30DAYSAGO" <= dr["DateCreated"])
{
Connection.Open();
SqlCommand Delete = new SqlCommand("DELETE FROM ForumPosts WHERE PostID = '" + dr["PostID"].ToString() +"'", Connection);
Delete.ExecuteNonQuery();
Connection.Close();
}
}
}
}

Any help / advice is appriciated! Thanks John

Meaby it is better if u do it in Sql code to select all data if is older than 30 days.. example

; //Pseudokod

Select * from ForumPosts where dataPost < DateTime.Now.AddDays(-30)//

and delete u can do it like this

delete from ForumPosts where dataPost < DateTime.Now.AddDays(-30)// Pseudokod

Sorry for my bad english

|||

No worrys that works much better thanks a million John

sql

Thursday, February 9, 2012

2005 - Remove Old Backups

Is there a way to remove backups older than a certain number of days with a
generic 2005 maintenance plan. I looked through the basic tasks available
and I did not see this option. There is an option to remove old history
(i.e. logs) but I did not see a task to remove old backups.
This functionality was available with the SQL Server 2000 maintenance plans.
Thanks!You didn't look hard enough<g>. There is a task for exactly that, deleting
old backup files. It is called the "Maintenance Cleanup Task".
Andrew J. Kelly SQL MVP
"Cgal" <cgallelli@.newsgroups.nospam> wrote in message
news:OcWhvIbBGHA.736@.TK2MSFTNGP10.phx.gbl...
> Is there a way to remove backups older than a certain number of days with
> a generic 2005 maintenance plan. I looked through the basic tasks
> available and I did not see this option. There is an option to remove old
> history (i.e. logs) but I did not see a task to remove old backups.
> This functionality was available with the SQL Server 2000 maintenance
> plans.
> Thanks!
>|||Hi Cgal,
As Andrew has mentioned, there does exists the Maintenance Task for
cleaning up backup files in the SQL 2005's Maintenance Plan items... (also
available in sql server 2000 through the maintenance plan creation
wizard...).
Create a new maintenance plan in sql2005 management studio, and in the
"Maintenance Plan Task" toolbox, choose the "Maintenance cleanup task",
there has setting for removing backup files of certain age of time....
#Maintenance Cleanup Task (Maintenance Plan)
http://msdn2.microsoft.com/en-us/library/ms177182.aspx
Thanks,
Steven Cheng
Microsoft Online Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
| From: "Andrew J. Kelly" <sqlmvpnooospam@.shadhawk.com>
| References: <OcWhvIbBGHA.736@.TK2MSFTNGP10.phx.gbl>
| Subject: Re: 2005 - Remove Old Backups
| Date: Tue, 20 Dec 2005 18:07:16 -0500
| Lines: 22
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
| X-RFC2646: Format=Flowed; Response
| Message-ID: <e2cIhobBGHA.3156@.TK2MSFTNGP12.phx.gbl>
| Newsgroups: microsoft.public.sqlserver.server
| NNTP-Posting-Host: c-24-128-28-245.hsd1.nh.comcast.net 24.128.28.245
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl microsoft.public.sqlserver.server:414948
| X-Tomcat-NG: microsoft.public.sqlserver.server
|
| You didn't look hard enough<g>. There is a task for exactly that,
deleting
| old backup files. It is called the "Maintenance Cleanup Task".
|
| --
| Andrew J. Kelly SQL MVP
|
|
| "Cgal" <cgallelli@.newsgroups.nospam> wrote in message
| news:OcWhvIbBGHA.736@.TK2MSFTNGP10.phx.gbl...
| > Is there a way to remove backups older than a certain number of days
with
| > a generic 2005 maintenance plan. I looked through the basic tasks
| > available and I did not see this option. There is an option to remove
old
| > history (i.e. logs) but I did not see a task to remove old backups.
| >
| > This functionality was available with the SQL Server 2000 maintenance
| > plans.
| >
| > Thanks!
| >
| >
|
|
|

2005 - Remove Old Backups

Is there a way to remove backups older than a certain number of days with a
generic 2005 maintenance plan. I looked through the basic tasks available
and I did not see this option. There is an option to remove old history
(i.e. logs) but I did not see a task to remove old backups.
This functionality was available with the SQL Server 2000 maintenance plans.
Thanks!
You didn't look hard enough<g>. There is a task for exactly that, deleting
old backup files. It is called the "Maintenance Cleanup Task".
Andrew J. Kelly SQL MVP
"Cgal" <cgallelli@.newsgroups.nospam> wrote in message
news:OcWhvIbBGHA.736@.TK2MSFTNGP10.phx.gbl...
> Is there a way to remove backups older than a certain number of days with
> a generic 2005 maintenance plan. I looked through the basic tasks
> available and I did not see this option. There is an option to remove old
> history (i.e. logs) but I did not see a task to remove old backups.
> This functionality was available with the SQL Server 2000 maintenance
> plans.
> Thanks!
>
|||Hi Cgal,
As Andrew has mentioned, there does exists the Maintenance Task for
cleaning up backup files in the SQL 2005's Maintenance Plan items... (also
available in sql server 2000 through the maintenance plan creation
wizard...).
Create a new maintenance plan in sql2005 management studio, and in the
"Maintenance Plan Task" toolbox, choose the "Maintenance cleanup task",
there has setting for removing backup files of certain age of time....
#Maintenance Cleanup Task (Maintenance Plan)
http://msdn2.microsoft.com/en-us/library/ms177182.aspx
Thanks,
Steven Cheng
Microsoft Online Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
| From: "Andrew J. Kelly" <sqlmvpnooospam@.shadhawk.com>
| References: <OcWhvIbBGHA.736@.TK2MSFTNGP10.phx.gbl>
| Subject: Re: 2005 - Remove Old Backups
| Date: Tue, 20 Dec 2005 18:07:16 -0500
| Lines: 22
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
| X-RFC2646: Format=Flowed; Response
| Message-ID: <e2cIhobBGHA.3156@.TK2MSFTNGP12.phx.gbl>
| Newsgroups: microsoft.public.sqlserver.server
| NNTP-Posting-Host: c-24-128-28-245.hsd1.nh.comcast.net 24.128.28.245
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP12.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl microsoft.public.sqlserver.server:414948
| X-Tomcat-NG: microsoft.public.sqlserver.server
|
| You didn't look hard enough<g>. There is a task for exactly that,
deleting
| old backup files. It is called the "Maintenance Cleanup Task".
|
| --
| Andrew J. Kelly SQL MVP
|
|
| "Cgal" <cgallelli@.newsgroups.nospam> wrote in message
| news:OcWhvIbBGHA.736@.TK2MSFTNGP10.phx.gbl...
| > Is there a way to remove backups older than a certain number of days
with
| > a generic 2005 maintenance plan. I looked through the basic tasks
| > available and I did not see this option. There is an option to remove
old
| > history (i.e. logs) but I did not see a task to remove old backups.
| >
| > This functionality was available with the SQL Server 2000 maintenance
| > plans.
| >
| > Thanks!
| >
| >
|
|
|

2005 - Remove Old Backups

Is there a way to remove backups older than a certain number of days with a
generic 2005 maintenance plan. I looked through the basic tasks available
and I did not see this option. There is an option to remove old history
(i.e. logs) but I did not see a task to remove old backups.
This functionality was available with the SQL Server 2000 maintenance plans.
Thanks!You didn't look hard enough<g>. There is a task for exactly that, deleting
old backup files. It is called the "Maintenance Cleanup Task".
--
Andrew J. Kelly SQL MVP
"Cgal" <cgallelli@.newsgroups.nospam> wrote in message
news:OcWhvIbBGHA.736@.TK2MSFTNGP10.phx.gbl...
> Is there a way to remove backups older than a certain number of days with
> a generic 2005 maintenance plan. I looked through the basic tasks
> available and I did not see this option. There is an option to remove old
> history (i.e. logs) but I did not see a task to remove old backups.
> This functionality was available with the SQL Server 2000 maintenance
> plans.
> Thanks!
>|||Hi Cgal,
As Andrew has mentioned, there does exists the Maintenance Task for
cleaning up backup files in the SQL 2005's Maintenance Plan items... (also
available in sql server 2000 through the maintenance plan creation
wizard...).
Create a new maintenance plan in sql2005 management studio, and in the
"Maintenance Plan Task" toolbox, choose the "Maintenance cleanup task",
there has setting for removing backup files of certain age of time....
#Maintenance Cleanup Task (Maintenance Plan)
http://msdn2.microsoft.com/en-us/library/ms177182.aspx
Thanks,
Steven Cheng
Microsoft Online Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
| From: "Andrew J. Kelly" <sqlmvpnooospam@.shadhawk.com>
| References: <OcWhvIbBGHA.736@.TK2MSFTNGP10.phx.gbl>
| Subject: Re: 2005 - Remove Old Backups
| Date: Tue, 20 Dec 2005 18:07:16 -0500
| Lines: 22
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
| X-RFC2646: Format=Flowed; Response
| Message-ID: <e2cIhobBGHA.3156@.TK2MSFTNGP12.phx.gbl>
| Newsgroups: microsoft.public.sqlserver.server
| NNTP-Posting-Host: c-24-128-28-245.hsd1.nh.comcast.net 24.128.28.245
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl microsoft.public.sqlserver.server:414948
| X-Tomcat-NG: microsoft.public.sqlserver.server
|
| You didn't look hard enough<g>. There is a task for exactly that,
deleting
| old backup files. It is called the "Maintenance Cleanup Task".
|
| --
| Andrew J. Kelly SQL MVP
|
|
| "Cgal" <cgallelli@.newsgroups.nospam> wrote in message
| news:OcWhvIbBGHA.736@.TK2MSFTNGP10.phx.gbl...
| > Is there a way to remove backups older than a certain number of days
with
| > a generic 2005 maintenance plan. I looked through the basic tasks
| > available and I did not see this option. There is an option to remove
old
| > history (i.e. logs) but I did not see a task to remove old backups.
| >
| > This functionality was available with the SQL Server 2000 maintenance
| > plans.
| >
| > Thanks!
| >
| >
|
|
|