Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Strange error, cannot script out jobs from SQL. Expand / Collapse
Author
Message
Posted Thursday, February 28, 2013 12:01 PM


SSChasing Mays

SSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing Mays

Group: General Forum Members
Last Login: Friday, November 4, 2016 10:08 AM
Points: 621, Visits: 585
When trying to script out a current job on our MSX sql server, we receive this error,"Unable cast object of type 'system.dbnull' to type 'system.string'. (microsoft.sqlserver.smo)"

I cannot find a lot of information on this topic. what would allow this job to run, yet prevent it from being scripted out and moved to our other MSX server?

It will work on some jobs, just not most of them. I do have SA on the box.


===================================

Script failed for Server '*******'. (Microsoft.SqlServer.Smo)

------------------------------
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=10.50.2500.0+((KJ_PCU_Main).110617-0026+)&EvtSrc=Microsoft.SqlServer.Management.Smo.ExceptionTemplates.FailedOperationExceptionText&EvtID=Script+Server&LinkId=20476

------------------------------
Program Location:

at Microsoft.SqlServer.Management.Smo.Scripter.ScriptWithList(DependencyCollection depList, SqlSmoObject[] objects)
at Microsoft.SqlServer.Management.Smo.Scripter.ScriptWithList(Urn[] urns, SqlSmoObject[] objects)
at Microsoft.SqlServer.Management.Smo.Scripter.Script(Urn[] urns, SqlSmoObject[] objects)
at Microsoft.SqlServer.Management.Smo.Scripter.EnumScript(Urn[] urns)
at Microsoft.SqlServer.Management.Smo.Scripter.Script(Urn[] urns)
at Microsoft.SqlServer.Management.UI.VSIntegration.ObjectExplorer.ScriptGenerator.ScriptCreate(SqlTextWriter sqlwriter, Server server, Urn[] urns, SqlScriptOptions options)
at Microsoft.SqlServer.Management.UI.VSIntegration.ObjectExplorer.ScriptNodeActionContext.Script(SqlTextWriter writer)
at Microsoft.SqlServer.Management.UI.VSIntegration.ObjectExplorer.SqlScriptMenu.OnScriptItemClick(Object sender, EventArgs e)

===================================

Unable to cast object of type 'System.DBNull' to type 'System.String'. (Microsoft.SqlServer.Smo)

------------------------------
Program Location:

at Microsoft.SqlServer.Management.Smo.Agent.Job.GetJobScriptingScript(StringBuilder createQuery, ScriptingOptions so)
at Microsoft.SqlServer.Management.Smo.Agent.Job.ScriptCreate(StringCollection queries, ScriptingOptions so)
at Microsoft.SqlServer.Management.Smo.Scripter.ScriptWithListWorker(DependencyCollection depList, SqlSmoObject[] objects)
at Microsoft.SqlServer.Management.Smo.Scripter.ScriptWithList(DependencyCollection depList, SqlSmoObject[] objects)


.
Post #1425236
Posted Thursday, February 28, 2013 7:16 PM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Friday, November 18, 2016 12:42 PM
Points: 2,947, Visits: 9,054
Maybe a version mis-match between Management Studio and the installed version of SQL ?


Post #1425326
Posted Thursday, February 28, 2013 10:36 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: 2 days ago @ 2:36 AM
Points: 7,933, Visits: 14,357
Check the owner of the job(s) in querstion. It may be owned by an SID that does not resolve to a valid login which could be giving SMO heartburn.

SELECT SUSER_SNAME(owner_sid)
FROM msdb.dbo.sysjobs
WHERE name = N'problem_job_name';


__________________________________________________________________________________________________
There are no special teachers of virtue, because virtue is taught by the whole community. --Plato
Post #1425348
Posted Friday, March 1, 2013 8:48 AM


SSChasing Mays

SSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing Mays

Group: General Forum Members
Last Login: Friday, November 4, 2016 10:08 AM
Points: 621, Visits: 585
I tried that just now, it resolves to a good name. I wonder why it states system.dbnull I cannot figure that one out.

These are Multiserver jobs. Though, even when targeted to the current server... it fails to script out.


.
Post #1425558
Posted Friday, March 1, 2013 10:04 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: 2 days ago @ 2:36 AM
Points: 7,933, Visits: 14,357
Sounds like a bug in SMO.

__________________________________________________________________________________________________
There are no special teachers of virtue, because virtue is taught by the whole community. --Plato
Post #1425613
Posted Friday, March 1, 2013 10:35 AM


SSChasing Mays

SSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing Mays

Group: General Forum Members
Last Login: Friday, November 4, 2016 10:08 AM
Points: 621, Visits: 585
opc.three (3/1/2013)
Sounds like a bug in SMO.


I agree. ^.^ I'm trying to track it down and fix it hopefully.


.
Post #1425626
Posted Friday, March 1, 2013 3:57 PM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Saturday, February 28, 2015 10:12 AM
Points: 329, Visits: 1,019
In addition to job owner, the "run as" of a step may be associated with an invalid SID.
Post #1425781
Posted Thursday, May 15, 2014 2:32 PM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Monday, September 12, 2016 4:41 PM
Points: 403, Visits: 824
I had also had this issue today on a test server (e.g., desktop). I've been defecting and re-mastering a lot. I changed my service account today as well - using my first MSA. Someplace one of my jobs (1 of about 60) got stuck as neither completely master or completely local. I could not save changes to it. I could not script it out - got the same error as you did.

I updated the system table for the job to remove the multi-server category. (In the past, I hacked a target job for fun to change it to a local job. I knew what to look for.)

update msdb.dbo.sysjobs
set category_id = 3
where name = 'MyJobNameWithTheIssue'

It was not enough because it had a related sysjobservers record with a non-zero server_id.

DELETE FROM js
FROM msdb.dbo.sysjobservers js
INNER JOIN msdb.dbo.sysjobs j
ON js.job_id = j.job_id
WHERE j.name = 'MyJobNameWithTheIssue'

This was enough. It became a local job that I could edit and script out. (I am very glad I did not have to cut and paste each step.)

PS There is a bug that will not let you remove the default instance as a target from a named instance master on the same machine. (I submitted a bug for this recently. The code is trying to insure that a target is not the master before deleting the job. Good thing to do after a host rename, but it fails to account for named instances.) I had to put the master on the default for testing. Perhaps the issue with this job is related to the bug.


Randy
Helpdesk: "Perhaps I'm not the only one that does not know what you are doing."
Post #1571530
Posted Tuesday, May 31, 2016 3:57 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Monday, October 31, 2016 10:45 AM
Points: 13, Visits: 187
I ran into this problem as well. For me, it was due to having history for defected servers still around. Essentially, there was job run history for servers where there was no longer a Server_id in the msdb.dbo.systargetservers table. Something in the scripting process saw those NULL Server_ids in the history and threw the error.

I found the solution on the following URL:
https://sqlsanctum.wordpress.com/2015/02/12/multi-server-job-scripting-failure/


You can quickly find if you have the same scenario with the query below (from the same URL):
SELECT
[JobName] = j.Name
,[JobServerId] = js.Server_id
,[TargetServerId] = ts.Server_id
FROM msdb.dbo.sysjobservers js
INNER JOIN msdb.dbo.sysjobs j ON j.job_id = js.job_id
LEFT JOIN msdb.dbo.systargetservers ts ON ts.server_id = js.server_id
WHERE j.category_id = 2 AND ts.server_id IS NULL


You can delete the history by running the command below (also from the same URL) which should allow you to script the job:
DELETE FROM js
FROM msdb.dbo.sysjobservers js
INNER JOIN msdb.dbo.sysjobs j ON j.job_id = js.job_id
LEFT JOIN msdb.dbo.systargetservers ts ON ts.server_id = js.server_id
WHERE j.name = 'JobName' AND ts.server_id IS NULL

Post #1791001
Posted Tuesday, May 31, 2016 4:16 PM


SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Today @ 1:12 PM
Points: 4,012, Visits: 4,735
Orlando Colamatteo (3/1/2013)
Sounds like a bug in SMO.

Agree with this.
I think I had that problem with SSMS 2008R2 and had to upgrade with the next CU in order to overpass it.




Igor Micev,
SQL Server developer at Seavus
www.seavus.com
Post #1791006
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse