Andrew Connell [MVP SharePoint]
1579 Posts |  42 Articles |  4864 Comments
.NET  |  MCMS  |  SharePoint  |  Office System
SharePoint Quick Links
Article Categories
Archives
Post Categories


Add to Technorati Favorites

My time for a mea culpa... but hey, at least I'm coming clean! Been meaning to post this for quite a while...

A while back I blogged about how to create custom tasks in WSS v3. In that post, and the subsequent article that provided more detail, I showed how you can use a WSS Feature to register the task upon activation... however I had a little oversight. The Feature was visible, meaning you could activate it from within the Site Settings ยป Site Collection Features page. Many tried to do this, but as you will see from the comments at the end of the article, ran into problems when they tried to activate the Feature. This is actually a good thing... because you shouldn't be able to do this!

Why? When activated via the Web interface, the Feature is activated using the application pool identity, which doesn't [and shouldn't] have sufficient rights to the farm's configuration DB where the specific stored procedure resides that is called when you register a job. So what was everyone's fix? Grant it rights... ooo... that's not good! What I should have done was make that feature non-visible and force you to be logged in with an account that has sufficient rights to the farm's configuration DB when activating the Feature. A small oversight, but one that confused quite a few people.

The code in the post and article have since been updated for future hits.

[Update 4/8/2008 @ 12a] A Visual How-To I created on the subject of creating custom timer jobs was recently posted on MSDN. You can get more info here.

[Update 5/1/2008 @ 730a] There is now an in-depth article on MSDN about creating custom timer jobs. If you have trouble please check this out as there is a ton of additional info here. Post: More Help on Creating Custom Timer Jobs

Technorati tags: , ,
posted on Monday, July 02, 2007 10:46 PM

Feedback

# Feature Properties 7/19/2007 4:21 PM Brian
Gravatar Andrew,

I have a little issue...I wrote a feature and we have multiple environments that this is deployed on. The problem is the databases are different, and so the connection strings are different. I tried putting the connection string in the feature.xml file, but couldn't seem to pull it out of there. Do you know how to pass properties in so certain things can be dynamic instead of all being hard-coded?

# re: Mea Culpa: Don't use visible Features to deploy custom tasks 7/19/2007 11:54 PM AC [MVP MOSS]
Gravatar Brian-
You can do this... you can add properties to the Feature definition file and retrieve those properties from the FeatureReceiver methods using the SPFeatureReceiverProperties.Definition.Properties collection. See the WSS v3 SDK.

# re: Mea Culpa: Don't use visible Features to deploy custom tasks 8/2/2007 2:13 PM Brian
Gravatar Andrew,

I'm still having issues doing this, when i go to install the feature i get

The platform does not know how to deserialize an object of type Microsoft.SharePoint.SPFeatureProperty. The platform can deserialize primitive types such as strings, integers, and GUIDs; other SPPersistedObjects or SPAutoserializingObjects; or collections of any of the above. Consider redesigning your objects to store values in one of these supported formats, or contact your software vendor for support.

in the feature.xml file i have:

<Properties>
<Property Key="ConnString" Values="Data Source=LCGDEV10;Initial Catalog=LCGAdmin;Integrated Security=True">
</Property>
</Properties>

and in my code for the installer i have:

taskTimerJob.Properties.Add("ConnString", properties.Definition.Properties["ConnString"]);


and in the timer code itself:

LCG.Admin.Framework.SqlHelper.DefaultConnectionString = Properties["ConnString"] as string;


Any help/thoughts would be appreciated.



# re: Mea Culpa: Don't use visible Features to deploy custom tasks 8/6/2007 1:33 PM Brian
Gravatar Andrew,

A slightly more interesting problem. The reason i was asking about the whole property stuff was because i'm trying to pass a connection string. I had the timer job working with the connstring hard coded (obviously not the way i want to do it). I went about changing stuff and that's when i was getting the above error. Now, the interesting part is i've tried to revert back to the old version with it hard coded (compared the two with windiff, they're exactly the same now) and restart iis and owstimer. So i go to install it again (again, after iis/owstimer restarts, new stuff in gac.) and i get this:

C:\Documents and Settings\bsteil>stsadm -o installfeature -name thinkwisetasktim
er

The platform does not know how to deserialize an object of type Microsoft.ShareP
oint.SPFeatureProperty. The platform can deserialize primitive types such as str
ings, integers, and GUIDs; other SPPersistedObjects or SPAutoserializingObjects;
or collections of any of the above. Consider redesigning your objects to store
values in one of these supported formats, or contact your software vendor for su
pport.

I don't understand why i'm getting this error when i'm trying to install the version that i used to have running.

-Brian

# re: Mea Culpa: Don't use visible Features to deploy custom tasks 9/13/2007 9:01 AM Rajesh Khatri
Gravatar Hi Andrew,

Thanks for a great post.

HOwever, in my case, execute is not being called.

1. I created a Service class and an installer class as described in your post.
2. i created a feature.xml file and mentioned the receiver assemby and class name.
3. i installed & activated this feature using stsadm utility.

I can see the feature (active) and job in timer job definitions. But seems service.Execute method is not being called.

Could you please suggest a way to resolve this or look for this?

Thanks again & regards,
Rajesh KHatri

# re: Mea Culpa: Don't use visible Features to deploy custom tasks 9/13/2007 9:58 PM AC [MVP MOSS]
Gravatar Rajesh-
Have you given it ample time to get started (15 minutes)? Try recycling the SharePoint timer service? What about checking the WSS logs? The event log?

# re: Mea Culpa: Don't use visible Features to deploy custom tasks 9/14/2007 2:22 AM Rajesh Khatri
Gravatar Hi Andrew,

Thanks for a quick response.
I have set the time to 5 minutes and have been waiting for a day now. Have restarted the timer services few times.

From WSS logs (C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\LOGS) I see there are 3 errors multiple time (remove word wrap)
OWSTIMER.EXE (0x1370) 0x0808 Windows SharePoint Services Topology Unexpected Can not access configuration database registry key: System.Security.SecurityException: Requested registry access is not allowed. at System.ThrowHelper.ThrowSecurityException(ExceptionResource resource) at Microsoft.Win32.RegistryKey.OpenSubKey(String name, Boolean writable) at Microsoft.Win32.RegistryKey.OpenSubKey(String name) at Microsoft.SharePoint.Administration.SPConfigurationDatabase.get_RegistryConnectionString() The Zone of the assembly that failed was: MyComputer
OWSTIMER.EXE (0x1370) 0x0808 Windows SharePoint Services Topology Monitorable An exception occured while trying to acquire the local farm: System.Security.SecurityException: Requested registry access is not allowed. at System.ThrowHelper.ThrowSecurityException(ExceptionResource resource) at Microsoft.Win32.RegistryKey.OpenSubKey(String name, Boolean writable) at Microsoft.Win32.RegistryKey.OpenSubKey(String name) at Microsoft.SharePoint.Administration.SPConfigurationDatabase.get_RegistryConnectionString() at Microsoft.SharePoint.Administration.SPConfigurationDatabase.get_Local() at Microsoft.SharePoint.Administration.SPFarm.FindLocal(SPFarm& farm, Boolean& isJoined) The Zone of the assembly that failed was: MyComputer
OWSTIMER.EXE (0x1370) 0x0808 Windows SharePoint Services Timer Unexpected The timer service could not initialize its configuration, please check the configuration database. Will retry later.

In event log there is following error (intermittently, not corresponding to above error)
SQL database login failed. Additional error information from SQL Server is included below.
Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON'.

Could you suggest some way to resolve? Please help.

Thanks and regards,
Rajesh Khatri


# re: Mea Culpa: Don't use visible Features to deploy custom tasks 9/14/2007 7:50 AM Rajesh Khatri
Gravatar Hi Andrew,

Thanks for a quick reply.
I have set the time to run after every 5 minutes and I am wainting for it since last one day. :)

Have recycled the timer service few times as well but it is not working.

About WSS logs (C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\LOGS)
I got the following error with OWSTimer.exe frequently.

09/14/2007 06:05:53.75
OWSTIMER.EXE (0x1370)
0x0808
Windows SharePoint Services
Topology
887x
Unexpected
Can not access configuration database registry key: System.Security.SecurityException: Requested registry access is not allowed.
at System.ThrowHelper.ThrowSecurityException(ExceptionResource resource)
at Microsoft.Win32.RegistryKey.OpenSubKey(String name, Boolean writable)
at Microsoft.Win32.RegistryKey.OpenSubKey(String name)
at Microsoft.SharePoint.Administration.SPConfigurationDatabase.get_RegistryConnectionString() The Zone of the assembly that failed was: MyComputer

09/14/2007 06:05:53.75 OWSTIMER.EXE (0x1370) 0x0808 Windows SharePoint Services Topology 88bl Monitorable
An exception occured while trying to acquire the local farm: System.Security.SecurityException: Requested registry access is not allowed.
at System.ThrowHelper.ThrowSecurityException(ExceptionResource resource)
at Microsoft.Win32.RegistryKey.OpenSubKey(String name, Boolean writable)
at Microsoft.Win32.RegistryKey.OpenSubKey(String name)
at Microsoft.SharePoint.Administration.SPConfigurationDatabase.get_RegistryConnectionString()
at Microsoft.SharePoint.Administration.SPConfigurationDatabase.get_Local()
at Microsoft.SharePoint.Administration.SPFarm.FindLocal(SPFarm& farm, Boolean& isJoined)
The Zone of the assembly that failed was: MyComputer

09/14/2007 06:05:53.75 OWSTIMER.EXE (0x1370) 0x0808 Windows SharePoint Services Timer 5utx Unexpected
The timer service could not initialize its configuration, please check the configuration database. Will retry later.

Could you please help me to resolve this issue with configuration?

PS: I tested this feature on another instance of share point server and it is working great there.

Thanks and regards,
Rajesh Khatri

# re: Mea Culpa: Don't use visible Features to deploy custom tasks 9/14/2007 7:55 AM AC [MVP MOSS]
Gravatar Rajesh-
Sorry man, those don't help me. You should open a ticket with MSFT CSS.

# re: Mea Culpa: Don't use visible Features to deploy custom tasks 9/18/2007 4:25 AM Rajesh khatri
Gravatar Hi Andrew,

sorry to trouble you again. I needhelp in solving following issue.

1. Time job has been deployed successfully on the server.
2. We have a custom workflow deployed on the server.
3. Whenever a new item is added to a My_Custom_List, workflow is kicked started.
4. now the timer job is expected to created new items in the My_Custom_List (which in turn should activate workflow)
5. timer job is adding an item in My_Custom_List but workflow is failing to start.
6. if we manually create an item in My_Custom_List, workflow is activated.

the error log entry is as following
OWSTIMER.EXE (0x0A20) 0x0F1C Windows SharePoint Services Workflow Infrastructure 72fs Unexpected
RunWorkflow: System.ArgumentException: Value does not fall within the expected range.
at Microsoft.SharePoint.Workflow.SPWorkflowActivationProperties..ctor(SPWorkflow workflow, Int32 runAsUserId, String associationData, String initiationData)
at Microsoft.SharePoint.Workflow.SPWinOEWSSService.MakeActivation(SPWorkflow workflow, SPWorkflowEvent e)
at Microsoft.SharePoint.Workflow.SPWinOeEngine.RunWorkflow(Guid trackingId, SPWorkflowHostService host, SPWorkflow workflow, Collection`1 events, TimeSpan timeOut)
at Microsoft.SharePoint.Workflow.SPWorkflowManager.RunWorkflowElev(SPWorkflow originalWorkflow, SPWorkflow workflow, Collection`1 events, SPRunWorkflowOptions runOptions)
Could you please help/guide to resolve the issue?

Thanks and regards,
Rajesh Khatri

# re: Mea Culpa: Don't use visible Features to deploy custom tasks 9/18/2007 7:26 AM AC [MVP MOSS]
Gravatar Rajesh-
You should debug your timer job to find out what is causing the issue in conjunction with looking at the logs. You'll need to attach to the OWSTIMER.EXE to debug.

# re: Mea Culpa: Don't use visible Features to deploy custom tasks 9/18/2007 11:50 AM Rajesh Khatri
Gravatar Hi Andrew,

I debugged the timer job. it runs absolutely fine without any errors & creates a new item in the list.

THis event (creation of new item) should trigger the workflow which is not happening. i am not able to debug the workflow component.

NOt sure which would it run under w3wp or owstimer?
Could you please suggest/

regards,
RAjesh Khatri

# re: Mea Culpa: Don't use visible Features to deploy custom tasks 9/27/2007 11:05 AM Clay
Gravatar Hi Andrew,

I have some seriously newbie questions. I am a complete novice with Sharepoint and most other MS technologies but I find myself with a need to learn how to set up a timer job like this post haste.

I am trying to test out the example and I can build, deploy it using the command line and deploy it as a solution in the central admin. -> solution management page. It shows up as a deployed solution fine. I can't find it on any other page though.

I am not the registered owner of the sharepoint install so I don't have root permissions on everything so I can't tell if the problem is simply one of permissions or if I have it misconfigured, etc.

Could you tell me how to configure the feature so that it shows up with less restrictive permissions, point me to some documentation on how to do so or suggest some other alternatives?

Thanks,
Clay

# re: Mea Culpa: Don't use visible Features to deploy custom tasks 10/23/2007 7:57 AM Andy Bruce
Gravatar Hi Andrew,

Saw an item in here asking about custom options, and also then the infamous "can't deserialize" which we've all run into. Thought you'd be interested in my approach, which is to provide a custom .config file that I search for based on the currently executing assembly. This allows emulation of dll.config functionality for all embedded object types (webparts, sitemap extensions, httpmodule extensions, and now timer jobs!). Config looks like this (note how namespaces used in key values so that I can combine multiple config files into a single easy-to-manage file:

<?xml version="1.0" encoding="utf-8" ?>
<!--
* Escc.WebParts.ThreatLevel.dll.config, ABr, 2007AUG14
* Custom configuration for generic ThreatLevel display part
-->
<configuration>
<appSettings>
<!-- logging values -->
<add key="Escc.WebParts.ThreatLevel.Logging.Sink.Count" value="1"/>
<add key="Escc.WebParts.ThreatLevel.Logging.Sink.1.Class" value="FileLoggerSink"/>
<add key="Escc.WebParts.ThreatLevel.Logging.Sink.1.Args" value="D:\WebPartLogs\Escc.WebParts.ThreatLevel.log"/>
<add key="Escc.WebParts.ThreatLevel.Logging.Sink.1.Enabled" value="true"/>

<!-- set logging by changing values below to one of IMMEDIATE, HIGH, MEDIUM, LOW, or TRACE -->
<add key="Escc.WebParts.ThreatLevel.Logging.Volume.FATAL" value="DEFAULT" />
<add key="Escc.WebParts.ThreatLevel.Logging.Volume.ERROR" value="DEFAULT" />
<add key="Escc.WebParts.ThreatLevel.Logging.Volume.WARNING" value="DEFAULT" />
<add key="Escc.WebParts.ThreatLevel.Logging.Volume.TRACE" value="DEFAULT" />
<add key="Escc.WebParts.ThreatLevel.Logging.Volume.INFO" value="DEFAULT" />
</appSettings>
</configuration>

To consume values dynamically:

Escc.CodeLibrary.Utils.ConfigReaders.BaseReader configReader = new Escc.CodeLibrary.Utils.ConfigReaders.SPWebPartReader(System.Reflection.Assembly.GetExecutingAssembly());
int num_sinks = configReader.AppSettingInt("Escc.WebParts.ThreatLevel.Logging.Sink.Count");

The approach works great since the config file location can be specified at runtime by the calling code, via a customizable Windows registry entry, and the library falls back to looking in "logical" places (e.g. folder where assembly is executing, up folders for running environment, SP install folder after dynamically determining SP installation in registry, and of course root folder(s) for hard disks). This approach works very nicely for situations where you want to customize any type of ASP.NET component without mucking with the application's web.config, and you have configuration info like db connections that you don't want to expose through a customizable UI to the end-user.

Cheers,

Andy

# re: Mea Culpa: Don't use visible Features to deploy custom tasks 10/23/2007 6:36 PM AC [MVP MOSS]
Gravatar Andy-
Cool solution! Thanks for posting!

# re: execute is not being called. 6/22/2008 2:55 PM Bharat Gadhia
Gravatar
Hi Andrew,

1. I created a Service class(TaskLoggerJob : SPJobDefinition) and an installer class(TaskLoggerJobInstaller:SPFeatureReceiver) as described in your post.
2. i created a feature.xml file and manifest.xml file and mentioned the receiver assemby and class name.
3. i installed & this feature using stsadm utility.

I can see the it under GlobalCofiguration in Solution Management But fail to detect in Timer Job Definitions. And also while in debug mode after attaching to owstimer.exe process it seems service.Execute method is not being called.

Could you please suggest a way to resolve this or look for this?

Thanks again & regards,
Bharat Gadhia.

# re: Mea Culpa: Don't use visible Features to deploy custom tasks 6/28/2008 9:45 AM AC [MVP MOSS]
Gravatar Bharat-
Look in the SP log files...

# re: Mea Culpa: Don't use visible Features to deploy custom tasks 9/4/2008 4:37 PM Tim Carlson
Gravatar I see a few references to the "can't deserialize" problem. I am getting that now too but can't seem to clear this up. Can you tell me what I have to do to clear this up?

# Daily, Monthly and Yearly Timer Jobs 10/29/2008 4:04 PM Nadeem Ahmed
Gravatar Hello Andrew,

I tried Minutes job and it works perfectly fine.. but I never got the daily, monthly and yearly timer jobs to work. They just don't fire up at the time I specify. The workaround I m using in my solution is to run the minute timer job every minute and in my code I m specifying the time to run a part of the code. Is there anything special, I've gotta do to make it happen?

Any help will be appreciated.

Thanks,


Post Feedback

Title:
Name:
Email:
(email will not be displayed)
Url:
Comments: 
Please add 6 and 1 and type the answer here:    
All Comments Are Filtered & Moderated
Unfortunately comment spammers are just too effecient and are constantly dirtying up blogs with irrelevant and unwanted comments trying to improve their standing on search engines. All comments on this blog are moderated. I do not censor comments, but I don't approve comments with vulger language or those soliciting products. Most of the time comments are approved within a few hours of being submitted with the only exception when I'm traveling.

Why are you asking for my email address?
The only reason I'm asking for your email address, which isn't required to submit a comment, is to provide a gravatar if you've created an account for yourself and associated your email address with a small image. If you have a gravatar created for the email address you submit, it will appear next to your comment. Otherwise nothing will appear.

What is a gravatar?
A gravatar is a "globally recognized avatar." You can get more information about gravatars, as well as create your own for free, at www.gravatar.com. You can also view my gravatar here.


Copyright © 2003 - 2010 Andrew Connell
Creative Commons License 
This work is licensed under a Creative Commons License
Site design by Heather Solomon.

 
 
MOSS WCM Training
Looking for MOSS 2007 WCM developer training? Look no further! I teach my 5-day hands-on and online WCM classes for developers I offer through my company: Critical Path Training.

Get more information on the WCM courses!