.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

Errors when trying to execute output of PowerScript to recreate jobs

Posted By:      Posted Date: April 10, 2011    Points: 0   Category :

I am using this code to create (script out) SQL Agent job create code to one file- I use the Advanced tab in the SQL Agent Step (Powerscript step) to output the results to the file.  I get errors from the output file when I try to parse or run it because the variables keep being redefined for each step. Can anyone help me?


[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo") | Out-Null
$srv = New-Object "Microsoft.SqlServer.Management.Smo.Server"
$srv.JobServer.Jobs | foreach {$_.Script()}


Msg 134, Level 15, State 1, Line 95

The variable name '@ReturnCode' has already been declared. Variable names must be unique within a query batch or stored procedure.

Msg 134, Level 15, State 1, Line 104

The variable name '@jobId' has already been declared. Variable names must be unique within a query batch or stored procedure.

Msg 132, Level 15, State 1, Line 243

The label 'QuitWithRollback' has already been declared. Label names must be unique within a query batch or stored procedure.

Msg 132, Level 15, State 1, Line 245

The label 'EndSave' has already been declared. Label names must be

View Complete Post

More Related Resource Links

Errors when using Proxy/Credentials to execute SQL Agent jobs that access SSIS packages


Running SQL Server 2008, on Windows Server 2008.

I'm having a problem trying to execute a job.  The job has executed successfully when I configure the SQL Agent account (domain account with sysadmin permissions in the instance) as the owner/executor of the job.  However, I want to tighten down security so I'm trying to use a proxy/credential.

Here are the steps I've followed:

1) create a non-privileged SQL account called "SQLJobOwner" that owns the job.

2) create a stored credential (domain account) that has an account on the local machine where the instance resides, and has "log on as batch" permissions.

3) created a login to the instance for the domain account that is stored as a credential, and granted sysadmin permissions to the account.

3) create a new proxy called "SSISProxy", and granted access to the SSIS subsystem.

4) Added job owner "SQLJobOwner" as a principal in the SSISProxy configuration window.

5) changed the job step that executes the SSIS package to "Run as" the "SSISProxy".


When I execute the job, the job fails with the following error:

Unable to start execution of step 1 (reason: Could not get proxy data for proxy_id = 1).  The step failed.

In addition, I get

How can I get a list of users that are able to start/stop/execute jobs on sql server?

I know that the users with sysadmin roles are able to start/stop/execute jobs but I wonder if there are another roles or permissions that enable users to do this.   regards,

Multiple-step OLE DB operation generated errors in Pre-Execute

Hello, I am getting below error; what could be the reason? The input is valid adn works good if I give to a multicast for test. But I get below error when I use OLEDB Destination ("table or view fast load") as my target. Note: Columns mappings are done auto by SSIS and All looks good as my source and destination are having same names as well. [Stage - Issue [33923]] Error: SSIS Error Code DTS_E_OLEDBERROR.  An OLE DB error has occurred. Error code: 0x80040E21. An OLE DB record is available.  Source: "Microsoft SQL Native Client"  Hresult: 0x80040E21  Description: "Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.". [Stage - Issue [33923]] Error: Cannot create an OLE DB accessor. Verify that the column metadata is valid. [DTS.Pipeline] Error: component "Stage - Issue" (33923) failed the pre-execute phase and returned error code 0xC0202025. Thanks, Prabhat

Execute a SSRS Report from CRM using URL to output to PDF with a specific file name


We have a CRM installation from which I am trying to do some reports which use the CRMAF filters so the reports are sensitive to entitiy selections.

eg execute a sales report for a number of selected accounts.

The specific RDLs have been created in VS2008 and uploaded to the reporting server via the Report import tools within CRM and all work as expected however the output of the report is in HTML via the web browser.

I have changed the configuration of the report in CRM so that it uses the URL method like below so that the report is rendered into PDF which is great.



This method prompts for the user to open/save the PDF file which is acceptable however I would like to replace the default file name (which is the report name) with one of my own.

For example rather

Execute SQL Tast output into a Variable in SSIS




I´m trying to put the count or the max value of an slq statement in to a variable and I´m not able until now.


I have a global variable named vMax and a OLE DB connection to a DB.

The Quiery works fine and a get a result depending of Count or Max from 15000 for Count and 2000849400 for Max.


I tried all Variable types as int16, int32, double,... nothing works and I get allways the same error mesage.


Error: 0xC001F009 at xyz: The type of the value being assigned to variable "User::vMax" differs from the current variable type. Variables may not change type during execution. Variable types are strict, except for variables of type Object.


I tried now everything and I was not able I have now only this execute SQL Task in my project and it does not work.


My goal is to copy all new records from Table1 in to Table2.

So I create an Execute SQL Tast to get the max ID and to use this for a sql command in the OLE DB Source.


Thank you in advance for any help.




Addition:  _____________________________________________________________________________

Im still trying to get this work and found one thing out. The ID that I'm using to find the Ma

"Collection was modified; enumeration operation may not execute" errors while crawling BCS .NET conn



I've been examining a problem where sharepoint 2010 search creates the following kind of errors when crawling external system created using .NET connector:
"Error while crawling LOB contents. ( Collection was modified; enumeration operation may not execute. )"

The error seems to occur randomly for about 0.5% of all the crawled items. Sharepoint log shows the following line:
10/22/2010 17:31:49.30     mssdmn.exe (0x36AC)                         0x0460    SharePoint Server Search          FilterDaemon                      e4ye    High        FLTRDMN: Errorinfo is "Collection was modified; enumeration operation may not execute."  [fltrsink.cxx:553]  d:\office\source\search\native\mssdmn\fltrsink.cxx     

If a visual studio debugger is attached to the mssdmn.exe when the exception is thrown, the call stack looks like this:
+        $exception    {"Collection wa

Getting Output value from a Stored Procedure in Execute SQL



I have an Execute SQL task ,in which I am having an stored procedure.

My requirement is I have to map the output value of sp to the output value of my Execute SQl Task.

So that once after the Execution of ExecuteSQL Task.I can have a check in precedence constraints and based on that I can move forward.

Thanks, A2H

SQL Agent Roles and the Ability of an AD Group to Execute Jobs

I would like to give an AD group the ability to execute Agent Jobs using the 2005 Agent roles (SQLAgentUserRole, etc) but you can not assign ownership of a job to a group. I have seen some work arounds and the only one I am considering is using a proxy account. Does anyone have any insight on doing this? This is certainly a fairly common thing to do, give support technicians the ability to run a job.  Running sql server 2005 standard ed, sp3 on a windows server 2003 standard r2 ed, thanks

Issue with SQL 2008 replication logreader errors The process could not execute 'sp_repldone/sp_repl


I noticed the log reader agent with the following errors on a production server.


The process could not execute 'sp_repldone/sp_replcounters' on 'DB_SERVER'.
The process could not execute 'sp_repldone/sp_replcounters' on 'DB_SERVER'.
The specified LSN {00037507:00003d5a:0005} for repldone log scan occurs before the current start of replication in the log {00037690:000015b5:0004}.
The process could not set the last distributed transaction.
The specified LSN {00037507:00003d5a:0005} for repldone log scan occurs before the current start of replication in the log {00037690:000015b5:0004}.
The process could not set the last distributed transaction.
The process could not execute 'sp_repldone/sp_replcounters' on 'DB_SERVER'.
The process could not execute 'sp_repldone/sp_replcounters' on 'DB_SERVER'.
The process could not execute 'sp_repldone/sp_replcounters' on 'DB_SERVER'.
The process could not execute 'sp_repldone/sp_replcounters' on 'DB_SERVER'.
The specified LSN {00037507:00003d5a:0005} for repldone log scan occurs before the current start of replication in the log {00037690:000015b5:0004}.
I then tried to check the Msrepl_transactions table for any information. This was blank, before hand I had noticed a high number of deadlocking going on with the distribution history tables on thesame publisher/distributor.

HttpContext.Items and Server.Transfer/Execute

The problem was basically that when a Server.Transfer call was applied the script container (and also various ClientScriptProxy script embedding routines) would potentially fail to load up the specified scripts.

Comma-Delimited Output

One of the common tasks performed when retrieving data from a SQL Server database is returning the result as a comma-delimited output instead of a result set. This task can be performed by using a CURSOR selecting the column to be concatenated together. Each row returned by the CURSOR is then concatenated together into a variable separating each one by a comma.

Enterprize library 4.1 getting output parameter after adding record in db, plz guide



I need to get output parameter (flag) from db after saving record in database. I am using Microsoft Enterprise Library 4.1 for DB. I am inserting record using I Data reader.

Please guide


want to execute url without showing that page or url to client.


hello friends,

I need ur help,what i want to do is to execute a url ("To send a text message to client") on client registration but without showing that url page, in short executing url without displaying any page or url to the client.

please help and thanks in advance.

How can I be sure that my entire project is up-to-date and free of errors in VS2010?


Seems like a stupid question, but I will go to Build > Build Solution many many times and the build will succeed many many times, then I will put in a minor syntax error and the build will fail, BUT the build will not fail because of the minor syntax error; it will fail because of an unresolved type that I put in about twenty compiles ago. And then I will fix the minor syntax eror, and the compiler will still complain about the unresolved type. Here is my code:

<%@ Register TagPrefix="FTB" Namespace="FreeTextBoxControls" Assembly="FreeTextBox" %>
  <form runat="server">
  Hello World!!  

Pretty simple, really. I go to Buld > Build WebApplication1 and it runs OK. Now, if I put in a minor syntax error, such as substitute "forrrrrrrm" for "form" and then try to Build Solution, it complains not about the misspelled word, but about the FreeTextBox. And then if I correct the misspelled wird, it still complains about the FreeTextBox. Which leads me to believe that Building the Solution does not check absolutely 100% everything that needs to be checked. Is there a more thorough way of compiling a program that I need to use?

Inline conditional output


Is it possible to somehow output some content based upon some conditional check in Razor? If not, I hope this possibility will be added in the future. What I want to do is the following:

<option value="1" @if(ListMode == 1) { = "selected=\"true\"" }>Full list</option>

As I can't figure out a way to do this, I have to either make a helper that does it for me or write duplicate code.

saving XML output from webservice


 I created a webservice that takes casenum as input and gives results as a dataset in an XML.

I could make a web client to display the resulting dataset in a grid view. Pls see my code copied below.

Now I want to create a console client that takes the casenum as input, to call the webservice and saves the resulting xml for further processing, but can't figure out how to just capture the xml to save. Here's the code for my web client. I would appreciate if you could help modify this tocapture the resulting xml to save file locally.

Thank You.

namespace ResultsWebServicesClient
    public partial class _Default : System.Web.UI.Page
        protected void Page_Load(object sender, EventArgs e)

        private void BindDataToGrid(string CaseNum)
            FG_Results results = new FG_Results();
            DataSet ds1 = new DataSet();
            ds1 = results.Get_FG_Results(CaseNum);
            GridView1.AutoGenerateColumns = true;
            GridView1.DataSource = ds1.Tables[0];

        protected void GetResults(object sender, EventArgs e)


Word Automation - Multiple DCOM Errors/Behavior

Before I get started, I already know that Microsoft does not support and highly discourages server-based MS Office automation.  I've read a multitude of posts and smarmy "*wink*, here's a link" replies, so I'm looking for actual help here, not condescending reprimands.

That notwithstanding, here is my problem.  I have developed a simple method that will open a local Word document, modify some header information, and then save the document as a new file.  As expected, it works great as a console/windows app, but as soon as I went to ASP.NET, DCOM jacked my world up when accessing the app remotely from a different domain account (that has access to the ASP.NET app.  For reference, my method is shown below:


1    public static string ModifyAndSaveBuildDocument(string localFilePath, BuildDocumentType docType, string buildNumber, DateTime buildDate, string projectName)
2            {
3                try
4                {
5                    ProjectConfiguration config = (ProjectConfiguration)ConfigurationManager.GetSection("ProjectConfiguration");
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend