Showing posts with label execute. Show all posts
Showing posts with label execute. Show all posts

Monday, March 26, 2012

proper way to drop publication?

Hi There

According to BOL, the correct procedure for deleting a publication are as follows:
These must be run on the publication database.

    Execute sp_dropsubscription to delete all snapshot subscriptions.

    Execute sp_droppublication to delete the publication and all of its articles.

My only issue is after step 1 the subscription still exists at the subscriber and it marked as failed (does not exist), i always have to go delete the subscription afterwards at the subscriber. AM i missing something? WHy does sp_dropsubscription not do this? Or is there another sp i should be running first?

Thanx

Hi Dietz,

The actual step to cleanup subscription depending on the subscription is push or pull. Basically, for push, you need to call sp_dropsubscription at publisher followed by sp_subscription_cleanup at subscriber. For Pull, you need to call sp_droppullsubscription at subscriber followed by sp_dropsubscription at pubisher.

Please refer to BOL topic "How to: Delete a Pull Subscription (Replication Transact-SQL Programming)" and "How to: Delete a Push Subscription (Replication Transact-SQL Programming)".

Thanks,|||Great thanx Peng, i wonder why they do not mention any of those sp's under the How to Delete Publications and Articles (Transact-SQL) BOL topic.
Also i cannot find

"How to: Delete a Pull Subscription (Replication Transact-SQL Programming)" and "How to: Delete a Push Subscription (Replication Transact-SQL Programming)".in BOL only TSQL references not Replication Transact sql programming.

I am using SS2000 not SS2005?

Thanx again|||Sorry, dietz. I made a bad assumption to think your system is SQL 2005. Sad My previous post really means for SQL 2005.

In SQL 2000 BOL, there is similar topic on how to drop subscription, depending on pull/push of the subscription. You probably already see it in "How To"->"Transact SQL" section.

Peng
sql

Monday, March 12, 2012

Programmertically create and execute stored procedure in SMO

Hi all,

I need to programmertically create and execute stored procedure in SMO, without registering it on the database. I also need to be able to load a file containing a stored procedure and execute it, using SMO.

Can someone show me how? A C# sample would be greatly appreciated.

Thanks in advance.

Hi,

a simple sample would be:

StoredProcedure sp = new StoredProcedure("SomeDatabase","usp_Somesp","SomeSchema");

sp.TextBody = "SELECT 'SomeData'";

Server s = new Server("SomeServer");

s.Databases["SomeDatabase"].StoredProcedures.Add(sp);

s.ConnectionContext.ExecuteNonQuery("usp_Somesp");

HTH, Jens K. Suessmeyer.

http://www.sqlserver2005.de

|||

Hi Jens,

I appreciate you help, but this is the error I get:

Error 1 'Microsoft.SqlServer.Management.Smo.StoredProcedureCollection' does not contain a definition for 'Add'

|||

Good morning ( for me 9:34 )

Look at this link http://msdn2.microsoft.com/en-us/library/ms162553.aspx

The Add is automatic when you use the Create method if you use the constructor

sp = new StoredProcedure(DataBaseName,StoredProcedureName)

Excuse me for my english

Have a nice day

|||Thank you very much.

Friday, March 9, 2012

Programmatically Evaluate Expression

I would like to evaluate expressions from within my execute function in a custom task. I saw this post from about 8 months ago detailing how it would be possible:

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=117564&SiteID=1

Is there an updated response (or more detailed example) to the question? Am I really risking a lot by using this undocumented feature?

Thanks!

Hi David,

To quote Kirk from the thread you linked:

"...this is not documented and will not be supported by Microsoft. It could change at anytime and break your component if you use it. User beware. "

This remains the case. I encourage you to head over to the MSDN Product Feedback site at http://msdn.microsoft.com/sql/bi/integration/ and submit a suggestion for exposing this functionality.

Thanks
Mark

|||

Thanks for the feedback. I have submitted the suggestion:

https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=133078

Wednesday, March 7, 2012

Programmatically Access The ExecuteProcessTask

Hi all,

I am trying to programmatically create an Execute Process Task in an SSIS package.

So far, I have the following:

Private package As Package
Dim th As TaskHost = TryCast(package.Executables.Add("STOCK:ExecuteProcessTask"), TaskHost)
th.Name = "Execute Process Task"
th.Description = "Execute Process Task"

That will get me the ExecuteProcessTask in my package that I want. But now, I would like to set the properties of it (i.e., the executable and arguments)

Basically, my IDE does not have any idea what an "ExecuteProcessTask" is. After lots of research, I cannot find out which assembly I need to reference in order to gain access to this object. In addition, whenever I try to Import the assembly that I think it is (i.e. Microsoft.SqlServer.ExecProcTask, or Microsoft.SqlServer.Dts.Tasks.ExecuteProcess), none of them work. I can see in my Assembly Cache that the .dll is registered correctly ...

What is going on?
What do you mean "none of them work"? When you set a reference to the Microsoft.SqlServer.ExecProcTask.dll then the code below should work.

Code Snippet

Dim execProc As Microsoft.SqlServer.Dts.Tasks.ExecuteProcess.ExecuteProcess = CType(th.InnerObject, Microsoft.SqlServer.Dts.Tasks.ExecuteProcess.ExecuteProcess)
execProc.Executable = "executable.exe"
execProc.Arguments = "/arguments"

|||Really, my problem is that I can't access the assembly that I need.

Basically, I need access to the Microsoft.SqlServer.Dts.Tasks.ExecProcTask assembly-

But, when I try to add a reference to it, I do not see it. In addition, with the interface in SSIS, I cannot "browse" for the assembly.

The only assembly that shows up in Intellisense is Microsoft.SqlServer.Dts.Tasks.ScriptTask

I am editing a script task- so what good is a script task if I can't access the assemblies I need?

What can I do?

|||Ah, you need to copy it from C:\Program Files\Microsoft SQL Server\90\DTS\Tasks to C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727. Then it will show up in your References.
|||Graahhhhh!! I just came up with that idea, tried it out and it worked- graahh-- wasted so much time and was so frustrated by that yesterday because of something so simple- I hate that!

Programmatically aborting a package

Can a package executed from code be aborted in code? The Package class has an Execute() method but no Abort() method. Clearly the debugger can stop a package at any point, so it must be possible somehow.

Are you trying to capture an error and then halt? If so, there's always the FireError event that can be thrown.|||

JeffJohnsonMVPVB wrote:

Can a package executed from code be aborted in code? The Package class has an Execute() method but no Abort() method. Clearly the debugger can stop a package at any point, so it must be possible somehow.

You're right, the debugger can do that but it might be a misnomer to think that that is the same as aborting from within thw package.

I presume that your abort code would be conditional so I would suggest that the best way to achieve what you want is to use conditional precedence constraints. If you need any help with those, feel free to reply.

-Jamie

|||

Okay, I need to expound. I have created a Windows service that executes SSIS packages. Many of these are long-running, perhaps for hours. If an operator realizes that something is wrong after submitting a package, I'd like to allow him to send a cancel request to the service and then have the service stop the package. What I do NOT want to do is code every single precedence constraint to check for an "abort" flag (and I'm not sure I'd even know how to set such a flag once the package has started without putting an MSMQ task or the like between each executable--yuck!). Could I simply kill the thread that is executing the package? That seems "dirty," and I was hoping for a cleaner method.

|||

I've taken a look at the application class (http://msdn2.microsoft.com/en-us/library/microsoft.sqlserver.dts.runtime.application_members.aspx) and the package class (http://msdn2.microsoft.com/en-us/library/microsoft.sqlserver.dts.runtime.package_members.aspx) and I don't see anything in there that would help.

I can understand why. An executing SSIS package is meant to be a batch/unattended process - once its running you just leave it to get on with it. I fear killing the process might be the way to go.

If you didn't want to put a conditional precedence constraint onto every executable then another option might be to put the executable that conditionally "kills" the package into the package container's OnPostExecute eventhandler. This *could* potentially be a little bit more "graceful" about it than just killing the process. Might be worth a try.

-Jamie

|||

There is a cleaner method. Call RunningPackage.Stop().|||

If your service is starting processes asynchronously your best bet is track the process id. The service could check periodically if the process had ended and "forget" the process if it had. That would give you a way to track what was currently running as well as select a process to kill.. If you want something intelligent in your logging, just have the service write to whatever you use for logging once the process has gone away. Maybe something like *** Operator Canceled ***|||

jaegd wrote:

There is a cleaner method. Call RunningPackage.Stop().

Does this work for file system based packages executed from command line dtexec or otherwise?|||

That looks perfect. I should've scanned the class library reference more thoroughly. I'll try to remember to let everyone know how it works.

(Clearly I don't know how to use the quoting feature, sorry.)

|||

Follow-up question: does anyone know if SSIS raises any particular events when RunningPackage.Stop is called? I could trap these events in my custom tasks and fail them cleanly if so.

|||

Yes the SSIS runtime does signal an event when RunningPackage.Stop() is called. You can get at that event by polling periodically -- call to FireQueryCancel() in a custom task, let's say, at strategic points.

If you don't want to poll, you could wrap the the system variable System::CancelEvent in a SafeHandle and wait for the event to be signalled. That also works.

SSIS stock tasks vary at the frequency which they check if the package's Cancel event has been signalled, but they do check it periodically (no, its not documented the frequency at which the runtime check's the cancel event's state).

|||

RunningPackage.Stop() works on package invoked by any "mechanism", since its the same runtime. That includes command line, BIDS, custom invocation util (whatever you can dream up, e.g. web service, windows service), not to mention in-process or out-of-process package executions via Execute Package tasks.

Saturday, February 25, 2012

Programatically find out stored procedures properties

Hi all,
How do I find out what id's have execute permissions on each procedure in a
database for all procedures using t-sql?
-Thanks! daveHi
I'm sure if you asks questions like this you know you way around SQL,
I did some searching in BOL since this is something that could be usefull
and I would in the future maybe use it.
So I came across this
A. List the permissions for a table
This example lists the permissions for the titles table.
EXEC sp_helprotect 'titles'
B. List the permissions for a user
This example lists all permissions that user Judy has in the current databas
e.
EXEC sp_helprotect NULL, 'Judy'
Now there's a lot of other "users info" tables and processes, so I'm sure if
you search BOL you'll find some usefull info. I'll search and see if I can
come up with something, and add it.
HTH
"dfate" wrote:

> Hi all,
> How do I find out what id's have execute permissions on each procedure in
a
> database for all procedures using t-sql?
> -Thanks! dave
>
>