Community Server on my mind

J-O Eriksson's blog


  • Running on CS 2.1 SP 2

    See top menu for subscription options

    Technology Blogs - Blog Top Sites

    BlogRankers.com

    Add to Technorati Favorites



Do you have problems with Community Server Database size?

If you have your Community Server web site at a hoster, have you been confronted with the issue of a growing CS Database?

In a conversation with Keyvan the other day, he pointed me to a forum thread at communityserver.org, and hinted that this might be a good idea for a CSJob. Wink In that thread a user wants to delete certain posts in the CS Database at certain intervals (although the question from the beginning is more like if mirrored blog posts does expire or if they have to be deleted manually).

Since I haven't had the time to find out which tables and which posts that would need to be deleted in this case, I thought I'd create a more general CSJob that could run any SQL Stored Procedure in the Community Server Database. This way this job could be used for much more that just deleting Mirrored Blog Posts. All you would need is to create a Stored Procedure for what you want to do.

So I created a CSJob, which I called CSSqlJob that takes one parameter. The name of the SQL Stored Procedure. You can't put any parameters on the Stored Procedure in this version. But I figured there might not be a great need for that.

So what is look like? To get a background on how to create a CSJob, you could take a look at Keyvan's article in the topic.

First I do the following imports to my code:


Click on the picture to see it in original size

Then in the Execute method of the CSJob, first read in the parameter for the SQL Stored Procedure (which you can set in communityserver.config where you declare the CSJob). Then run the Stored Procedure, and if anything goes wrong let's write that to the Community Server Event Log.


Click on the picture to see it in original size

The code for running the Stored Procedure just creates a connection object and a command object and executes the command. As you can see I also declare the type of the command to be a Stored Procedure.


Click on the picture to see it in original size

So how do I get the connection string? Well, in this case I've used the SQLCommonDataProvider.


Click on the picture to see it in original size

And to create an entry in the CS Event Log in case something goes wrong the following code is run.


Click on the picture to see it in original size

After this just compile the code, and put the DLL in you CS Bin folder, and put an entry like the following in the 'Jobs' section of your communityserver.config file.


Click on the picture to see it in original size

Now this code has been written pretty fast just as an example. I don't know if this is the best way to do it performance and/or security wise. But it works! Feel free to give any comments on the code.

If you don't want to build this DLL yourself, you can download it from my downloads area.

So with this CSJob, you should be able to do any job a Stored Procedure can do on your CS Database on a scheduled basis. Now it's just a matter of writing that Stored Procedure to do what you want!

If you enjoyed this post Subscribe to my feed via RSS or e-mail!
Posted: Wednesday, November 29, 2006 8:48 PM by J-O Eriksson

Comments

Community Server Daily News said:

news of the day a grab bag for what's happening in Community Server Jason Alexander answer's Don Dodge's

# November 29, 2006 1:41 PM

Chris Lotter said:

Really cool and very clever!  Thanks for this!

# November 29, 2006 2:33 PM

Keyvan Nayyeri said:

Good job, J-O :-)

# November 29, 2006 11:02 PM

J-O Eriksson said:

Thanks Chris and Keyvan!

Now it's just a matter of having a few good SQL Script. Maybe I add some script samples to the CSSQLJob package later on.

If you have any that should be included, let me know. Of course I'd credit you for them in the package.

# November 30, 2006 4:00 AM

Keyvan Nayyeri said:

# November 30, 2006 4:30 AM

Community Server Daily News said:

from the editor occasional messages that don't fit anywhere else If you were on CommunityServer.org between

# December 1, 2006 1:59 PM

Announcements said:

This week... J-O Eriksson provides an overview of the Community Server Service Pack upgrade process with

# December 1, 2006 2:54 PM

Community Server said:

This week... J-O Eriksson provides an overview of the Community Server Service Pack upgrade process with

# January 19, 2007 6:21 PM

Community Server Bits said:

The King of All CSModules has eyes on the CSJobs prize with this descriptive post on creating a Community

# March 12, 2007 5:01 AM

Community Server on my mind said:

If you're using the Reader application in Community Server , did you know that the posts never expire and will over time add to the size of your database? Last Friday I wrote an article about how you can create a CSJob that lets you run a SQL Stored Procedure

# May 2, 2008 3:44 AM

Charles Smith said:

Not really useful. How about an .exe I can run from my PC that will log into my SQL database on my shared hosting site and delete whatever it is that causes the database to grow so much. I don't want to schedule things, I just want to once a year trim all the posts or attachments or whatever that causes the database to grow so uncontrollably.

Charles.

# July 29, 2008 9:13 PM

J-O Eriksson said:

Charles,

I guess you can do an .EXE with just the RunSQLCommand method above. Change that method to take a parameter for the CommandName variable, which you provide via a Forms App together with the connection string.

# July 29, 2008 10:34 PM
Leave a Comment

(required) 

(required) 

(optional)

(required) 

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS