Sharepoint 2013 Custom Timer Job running on development server but not on production server - sharepoint

I have developed a custom timer job for SharePoint 2013 in visual studio 2012 which sends email notifications. The issue is that it works fine on development server.
I have followed the following steps to debug it on the development server 1.) Deploy the timer job on respective site. 2.) Restart the timer service in services.msc 3.) Then is do attach to process OWSTIMER in visual studio. 4.) And finally Go to SharePoint 2013 Central administration->Monitoring->Review Job Definition and click on the respective timer job and say run now.
After doing this the breakpoint is hit in visual studio at the Execute() method. So in the development server it is running.
Now on the production server I cannot debug using visual studio so I have deployed the packaged solution(.wsp).
I can see the feature is activated in Site Collection Administration-> Site Collection Features.
Now on the production server I follow the following steps 1.)Restart the timer service in services.msc 2.)And finally Go to SharePoint 2013 Central administration->Monitoring->Review Job
Further to test whether the timer job is working on production server or not I had used PortalLog.LogString("Flow test1"); at the start of the Execute() method. Now this runs on the development server and I see the message in the SharePoint logs but on the production server I can't see "Flow Test1" in the logs after I click Run Now in central admin.
Can anyone suggest what is the issue and a possible solution?

It seems to me that there are two issues:
You should use other way for logging LoggingService should be preferred way. Use WriteEvent to write to EventLog or WriteTrace to write to ULS log.
Running job. Be sure that Owstimer.exe service on all web servers are restarted (can be done by this powershell script). I expect that you have correctly scheduled your job either in your powershell script or in your feature receiver.

Here are a few things to try:
Go to Central Administration and run the timer job from there. Then go to the job history page and check whether it finished successfully or not. If there was an error, you should see the error message from there. That will give you a clue on whats happening.
As Mazin said, restart the timer service in all servers. After deployment, the DLLs are cached by the process and you don't see your changes reflected.
Browse the SharePoint logs and search for an exception or error. You can narrow your search by selecting the timeframe on which your job ran. You can use the following PS script:
Get-SPLogEvent -StartTime "02/02/2014 11:00" -EndTime "02/02/2014 13:00" | Out-GridView

As stated here it seems your job assembly is not deployed in the GAC. Verify that the assembly is present there.

Related

SharePoint 2016 some Timer Jobs run time n/a

I'm helpless... Since couple of weeks looking for a solution.
Some TimerJobs (system jobs and custom) in my migrated SharePoint farm won't be executed. Migrated from 2010, over 2013 to 2016.
Last run time is: N/A or via powershell 01.01.0001 00:00:00
I spend a lot of time to look for a solution, and already did the following:
Restarted timer service
Restarted all servers
iis reset
Cleared SharePoint configuration cache
Tried "Start-SPAdminJob -verbose", but it fails (also when I do "net stop SPAdminV4 / net start SPAdminV4")
Started SharePoint Configuration Wizard
Redployed the wsp and reactivated (for a custom timer job)
Checked service accounts
I'm also wondering about that some of them have also no web application associated. Is this normal?
Web application: N/A
Is there someone with an idea?
Thanks for any help.
try shell
$server=Get-SPServer -Identity "name"
$ts = $server.ServiceInstances | ? { $_.GetType().Name -like "*sptimerservice*" } | Select -First 1
$ts.AllowContentDatabaseJobs = $true
$ts.AllowServiceJobs = $true
$ts.Update()
About the custom jobs it may be related to missing deployment steps, like WSPs installation (ex. Compatibility Level or something else) or even feature activation to 'attach' it to a web application, service instance or server. Remembering that we have a sort of 'scopes' that must be checked during time job development. This is not new, but an excellent material:
https://www.red-gate.com/simple-talk/dotnet/.net-tools/a-complete-guide-to-writing-timer-jobs-in-sharepoint-2010/
About the system (native) jobs, I recommend you to give us an example, so we may check the SharePoint 2016 TimerJobs reference list:
https://learn.microsoft.com/en-us/sharepoint/technical-reference/timer-job-reference-for-sharepoint-server-2016
After checking those requirements, you have a way to start some stucked jobs (or force them to run immediately), using the following commands on your SharePoint shell:
net stop spadminv4
stsadm -o execadmsvcjobs
net start spadminv4
Reference: https://technet.microsoft.com/pt-br/library/cc262783(v=office.12).aspx
And one last shot - check if you have pending administrative changes, like running PSConfig. Central Admin Health Analyzer is your best friend ;)
Bonus: about custom timer jobs, please always be sure that some features may require the Microsoft SharePoint Foundation Web Application service started on CA Server, to make custom timer jobs available under Central Admin:
https://learn.microsoft.com/en-us/SharePoint/administration/service-deployment-planning
"This service provides web server functionality. It is started by default on web servers. Custom features scoped to web applications may not display in Central Administration as intended if this service is not started on the server running Central Administration and if the feature cannot be deployed globally."

Unable to debug Azure webjobs - the webjob processes do not show in the "Attach to process" dialog

Visual Studio 2013 update 3. I have deployed several Webjobs to Azure, both manually (upload a bundle via the portal) and also published directly from Visual Studio. The webjobs I am testing with are set to run "Continuous" and have code that runs inside a while(true) {} loop; so the process never ends. The webjobs are functioning properly and I see their runtime output in the Webjobs dashboard log output screen.
I've enabled remote debugging on the website. When I select Debug, Attach to process, the webjob process names never show on the list. All I see are the remote debugger processes and w3wp.exe.
Ideas?
Instead of attaching to SITENAME.azurewebsites.net, try to attach to SITENAME.scm.azurewebsites.net. Use same credentials as for the regular debugging connection. WebJobs run under a different context (Kudu), hence the different endpoint.

SharePoint 2007 WSP deployment process, restarting SPTimerV3 service

I've got a WF feature which I've been deploying into my development/test environment fairly frequently, and as such have run into an issue where the assembly seems to be cached by the SharePoint Timer service (SPTimerV3), and then an out-of-date version is used after the workflow rehydrates following a Delay Activity.
To fix this, I've tried adding a "NET STOP SPTimerV3" and "NET START SPTimerV3" to my batch file after the STSADM commands to install the .WSP . It works to restart the timer service, and I no longer have the caching problem, however restarting the timer this way seems to kill my SP App Pools in IIS fairly regularly.
Has anyone found a good way to restart the timer in a WSP deployment batch file without adverse affects? Do I need to restart another dependent service, or restart the App Pools each time as well?
you need to restart IIS as well. IISRESET /noforce should do the trick.

Automatically Restarting Website after IIS AppPool recyle

I'm using a website which interacts with SQL Server Agent in order to schedule the automatic processing and emailing of reports. I recently noticed that when the AppPool recyles, that i'm not getting reports afterwards - until someone logs into the website again. It's possible for the website not to get hit for hours/days, during which all the scheduled tasks are lost.
I'd like to set up a windows task to either run periodically or trigger off the AppPool recycle event. But I'm not sure what the task should be. I had one suggestion to set up a Windows task to exercise a .js script that would hit the website, but this only works with Windows Authentication (which isn't being used):
var xmlhttp = new ActiveXObject("MSXML2.XMLHTTP");
xmlhttp.open("POST", "http://localhost/website/default.aspx", false);
xmlhttp.send();
Looking for some suggestions on how to "wake up" a website after an IIS AppPool recycle.
Thanks.
ab.
Why not run gnu wget from a scheduled task:
wget -O - http://mysite.com/default.aspx
I ran across this today which seems like it might help you out. It's the IIS Warm-up module. Depends on whether you can convince the your customer to install it, although it is an official IIS module, so hopefully it's no problem.

Script to check IIS running or not

I would like to write a script to start IIS server automatically if it is stopped.
You can use the IIS Admin Scripts to query the server, and then start it if you need.
The script is located in %systemroot%\system32.
To query you server, just run IIsWeb.vbs /query w3svc/1 from a command line.
If it's not running, then you can run IIsWeb.vbs /start w3svc/1 to start it.
Here is an article with more information on these scripts.
you can look for w3wp.exe in the process list (if it's IIS6)
you can always try "iisreset /start" - I believe, it works even if IIS is already started
take a look at the scripts provided by Microsoft in C:\Inetpub\AdminScripts (assuming default install location), there is startsrv.vbs, startweb.vbs - both do a good job
One simple thing you can do if you are worried about iis not restarting after it fails is to set the services responses. If you go into services and then look at the properties for iis, you will see a recovery tab. Change each of the failure options to restart the service. one thing you could also do is create a batch file that includes
iisreset
and set the option to run program and have that be the program you select.
Found some code here: https://social.msdn.microsoft.com/Forums/en-US/5a01d88b-2b7c-4d0b-bce0-9b90a236b64a/how-to-check-if-iis-is-running?forum=asmxandxml
Example:
Dim sc As New System.ServiceProcess.ServiceController("World Wide Web Publishing Service")
If sc.Status.Equals(System.ServiceProcess.ServiceControllerStatus.Stopped) Or sc.Status.Equals(System.ServiceProcess.ServiceControllerStatus.StopPending) Then
' Start the service if the current status is stopped.
sc.Start()
Else
' Stop the service if its status is not set to "Stopped".
sc.Stop()
End If

Resources