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

Monday, March 26, 2012

Script to grant execute for sprocs

Hello.

I'm using what looks to be a popular script to grant execute privileges to stored procedures, and it works great as long as the user account that you want to grant to is not a domain account.

For example, I need to grant execute to myDomain\dbUsers, but get a syntax error when the script tries to execute this statement:

SET @.SQL = 'GRANT EXECUTE ON [' + @.Owner

+ '].[' + @.StoredProcedure

+ '] TO myDomain\dbUsers'

Incorrect syntax near '\'.

The script works fine if a non-concatenated user account is given.

We use Active Directory to manage our access, thus the domain\group.

Has anyone found a way around this?

Thanks in advance.

Tess

Here's the entire script for anyone who's interested:

USE whateverDatabase

GO

DECLARE @.SQL nvarchar(4000),

@.Owner sysname,

@.StoredProcedure sysname,

@.RETURN int

-- Cursor of all the stored procedures in the current database

DECLARE cursStoredProcedures CURSOR FAST_FORWARD

FOR

SELECT USER_NAME(uid) Owner, [name] StoredProcedure

FROM sysobjects

WHERE xtype = 'P'

AND OBJECTPROPERTY(OBJECT_ID(QUOTENAME(USER_NAME(uid)) + '.' + QUOTENAME(name)), 'IsMSShipped') = 0

AND name LIKE 'p%'

OPEN cursStoredProcedures

-- "Prime the pump" and get the first row

FETCH NEXT FROM cursStoredProcedures

INTO @.Owner, @.StoredProcedure

-- Set the return code to 0

SET @.RETURN = 0

-- Encapsulate the permissions assignment within a transaction

BEGIN TRAN

-- Cycle through the rows of the cursor

-- And grant permissions

WHILE ((@.@.FETCH_STATUS = 0) AND (@.RETURN = 0))

BEGIN

-- Create the SQL Statement. Since we’re giving

-- access to all stored procedures, we have to

-- use a two-part naming convention to get the owner.

SET @.SQL = 'GRANT EXECUTE ON [' + @.Owner

+ '].[' + @.StoredProcedure

+ '] TO myDomain\dbUsers'

-- Execute the SQL statement

EXEC @.RETURN = sp_executesql @.SQL

-- Get the next row

FETCH NEXT FROM cursStoredProcedures

INTO @.Owner, @.StoredProcedure

END

-- Clean-up after the cursor

CLOSE cursStoredProcedures

DEALLOCATE cursStoredProcedures

-- Check to see if the WHILE loop exited with an error.

IF (@.RETURN = 0)

BEGIN

-- Exited fine, commit the permissions

COMMIT TRAN

END

ELSE

BEGIN

-- Exited with an error, rollback any changes

ROLLBACK TRAN

-- Report the error

SET @.SQL = 'Error granting permission to ['

+ @.Owner + '].[' + @.StoredProcedure + ']'

RAISERROR(@.SQL, 16, 1)

END

GO

Just like with table and other object names, if the user contains special characters it must be "quoted" so, add either [] or "" around the user

|||

Thank you very much!

Tess

sql

Friday, March 23, 2012

Script to assign task name to a variable

Hi,

I have a OnPre Execute event on a task in SSIS. I want to be able to assign the parent task name to this event to a variable.

I am using a script task. Are there any examples available on how to achieve this?
I have looked at the DTSProperty, but have to admit that I am struggling with this.Tongue Tied

Once I have assigned the taks name to the varaible, I can then use my bubble up error handler, and still be able to log the name of the task which caused the error.

Many thnaks

RudyThe name of the task (more accurately - the container) that threw the event is available in the System::SourceName variable in the eventhandler.

Is that what you want?

Here's an example of doing something very similar: http://blogs.conchango.com/jamiethomson/archive/2005/06/11/1593.aspx

-Jamiesql

Wednesday, March 21, 2012

Script Task working in Visual Studio but not when the package is run by a job?

I have a script that changes the name of a file after a data upload. The script works fine if I execute the package in Visual Studio but when I run the file package from a SQL server job it does not rename the file. The data does get uploaded it just does not run the final script.

Any help would be appreciated.

Steve

Have you enabled logging to get the error?

The problems when running under Agent are mostly related to authentication and permissions issues - as the job probably runs under different credentials compared to interactive execution. Your options are either configure job to run under your account, or fix the permissions to allow job account to perform the operation that is failing.

See this KB for troubleshooting steps:
http://support.microsoft.com/kb/918760

Script Task scripts will not stop at breakpoints.

I can not debug any of my scripts. They execute just fine, but if I have a breakpoint set in the script code (in VSA), I get the message:

SQL server integration services script task has encountered a problem and needs to close. We are sorry for the inconvenience.

If you were in the middle of something, the information you were working on might be lost.

Debug Close

When I choose "Close" I get this:

sMicrosoft Visual Studio for Applications has lost the link to .

Your work will be exported to <<my Local Settings My Documents path>> when you quit the application.

OK

When I click "OK" my package executes normally, but no breakpoints will fire from that point on.

No need to post your message twice....

Script Tasks, not Script Components, correct?

One workaround is to use a MSGBOX().|||I was in the process of deleting my other post when you replied. I didn't want to post in a thread that had something marked as an answer. Yes, this is for script tasks. I certainly could use MsgBox() but that is hardly an answer to this problem. I could also write text out to a file, call a web service, insert a record into a table, etc. None of those things take the place of stepping through code. Is there a fix in the works for this issue? It really makes script tasks of limited use, or at least it makes them take much longer to develop.|||And you are following these steps?

http://technet.microsoft.com/en-us/library/ms140033.aspx|||With the exception of right-clicking (I was clicking in the margin to set the breakpoint), yes, that is exactly what I did.|||Do you have any SQL Server service packs applied?|||How would I tell?|||

JWardRogers wrote:

How would I tell?

In BIDS, go to Help->About and select SSIS. What is the version number reported there?|||9.00.1399.00|||That's the original.

Try grabbing the SQL Server Service Pack 2 and installing that. Many fixes are contained in SP1 and SP2 as well.|||

Phil Brammer wrote:

That's the original.

Try grabbing the SQL Server Service Pack 2 and installing that. Many fixes are contained in SP1 and SP2 as well.

But unfortunately not the fix for my problem. :-(

SP2 is installed and it is still behaving the same way.

Version is now 9.00.3042.00

|||

I'm still having the same problem...

|||XP? Vista?|||

Server 2003 version 5.2.3790 (service pack 1.0)

Hot Fix: KB931836

4GB RAM

|||

JWardRogers wrote:

Server 2003 version 5.2.3790 (service pack 1.0)

Hot Fix: KB931836

4GB RAM

Do you also develop on a local workstation? Have you tried breakpoints on that if so?

Script Task scripts will not stop at breakpoints.

I can not debug any of my scripts. They execute just fine, but if I have a breakpoint set in the script code (in VSA), I get the message:

SQL server integration services script task has encountered a problem and needs to close. We are sorry for the inconvenience.

If you were in the middle of something, the information you were working on might be lost.

Debug Close

When I choose "Close" I get this:

sMicrosoft Visual Studio for Applications has lost the link to .

Your work will be exported to <<my Local Settings My Documents path>> when you quit the application.

OK

When I click "OK" my package executes normally, but no breakpoints will fire from that point on.

No need to post your message twice....

Script Tasks, not Script Components, correct?

One workaround is to use a MSGBOX().|||I was in the process of deleting my other post when you replied. I didn't want to post in a thread that had something marked as an answer. Yes, this is for script tasks. I certainly could use MsgBox() but that is hardly an answer to this problem. I could also write text out to a file, call a web service, insert a record into a table, etc. None of those things take the place of stepping through code. Is there a fix in the works for this issue? It really makes script tasks of limited use, or at least it makes them take much longer to develop.|||And you are following these steps?

http://technet.microsoft.com/en-us/library/ms140033.aspx|||With the exception of right-clicking (I was clicking in the margin to set the breakpoint), yes, that is exactly what I did.|||Do you have any SQL Server service packs applied?|||How would I tell?|||

JWardRogers wrote:

How would I tell?

In BIDS, go to Help->About and select SSIS. What is the version number reported there?|||9.00.1399.00|||That's the original.

Try grabbing the SQL Server Service Pack 2 and installing that. Many fixes are contained in SP1 and SP2 as well.|||

Phil Brammer wrote:

That's the original.

Try grabbing the SQL Server Service Pack 2 and installing that. Many fixes are contained in SP1 and SP2 as well.

But unfortunately not the fix for my problem. :-(

SP2 is installed and it is still behaving the same way.

Version is now 9.00.3042.00

|||

I'm still having the same problem...

|||XP? Vista?|||

Server 2003 version 5.2.3790 (service pack 1.0)

Hot Fix: KB931836

4GB RAM

|||

JWardRogers wrote:

Server 2003 version 5.2.3790 (service pack 1.0)

Hot Fix: KB931836

4GB RAM

Do you also develop on a local workstation? Have you tried breakpoints on that if so?sql

Script Task scripts will not stop at breakpoints.

I can not debug any of my scripts. They execute just fine, but if I have a breakpoint set in the script code (in VSA), I get the message:

SQL server integration services script task has encountered a problem and needs to close. We are sorry for the inconvenience.

If you were in the middle of something, the information you were working on might be lost.

Debug Close

When I choose "Close" I get this:

sMicrosoft Visual Studio for Applications has lost the link to .

Your work will be exported to <<my Local Settings My Documents path>> when you quit the application.

OK

When I click "OK" my package executes normally, but no breakpoints will fire from that point on.

No need to post your message twice....

Script Tasks, not Script Components, correct?

One workaround is to use a MSGBOX().|||I was in the process of deleting my other post when you replied. I didn't want to post in a thread that had something marked as an answer. Yes, this is for script tasks. I certainly could use MsgBox() but that is hardly an answer to this problem. I could also write text out to a file, call a web service, insert a record into a table, etc. None of those things take the place of stepping through code. Is there a fix in the works for this issue? It really makes script tasks of limited use, or at least it makes them take much longer to develop.|||And you are following these steps?

http://technet.microsoft.com/en-us/library/ms140033.aspx|||With the exception of right-clicking (I was clicking in the margin to set the breakpoint), yes, that is exactly what I did.|||Do you have any SQL Server service packs applied?|||How would I tell?|||

JWardRogers wrote:

How would I tell?

In BIDS, go to Help->About and select SSIS. What is the version number reported there?|||9.00.1399.00|||That's the original.

Try grabbing the SQL Server Service Pack 2 and installing that. Many fixes are contained in SP1 and SP2 as well.|||

Phil Brammer wrote:

That's the original.

Try grabbing the SQL Server Service Pack 2 and installing that. Many fixes are contained in SP1 and SP2 as well.

But unfortunately not the fix for my problem. :-(

SP2 is installed and it is still behaving the same way.

Version is now 9.00.3042.00

|||

I'm still having the same problem...

|||XP? Vista?|||

Server 2003 version 5.2.3790 (service pack 1.0)

Hot Fix: KB931836

4GB RAM

|||

JWardRogers wrote:

Server 2003 version 5.2.3790 (service pack 1.0)

Hot Fix: KB931836

4GB RAM

Do you also develop on a local workstation? Have you tried breakpoints on that if so?

Script Task scripts will not stop at breakpoints.

I can not debug any of my scripts. They execute just fine, but if I have a breakpoint set in the script code (in VSA), I get the message:

SQL server integration services script task has encountered a problem and needs to close. We are sorry for the inconvenience.

If you were in the middle of something, the information you were working on might be lost.

Debug Close

When I choose "Close" I get this:

sMicrosoft Visual Studio for Applications has lost the link to .

Your work will be exported to <<my Local Settings My Documents path>> when you quit the application.

OK

When I click "OK" my package executes normally, but no breakpoints will fire from that point on.

No need to post your message twice....

Script Tasks, not Script Components, correct?

One workaround is to use a MSGBOX().|||I was in the process of deleting my other post when you replied. I didn't want to post in a thread that had something marked as an answer. Yes, this is for script tasks. I certainly could use MsgBox() but that is hardly an answer to this problem. I could also write text out to a file, call a web service, insert a record into a table, etc. None of those things take the place of stepping through code. Is there a fix in the works for this issue? It really makes script tasks of limited use, or at least it makes them take much longer to develop.|||And you are following these steps?

http://technet.microsoft.com/en-us/library/ms140033.aspx|||With the exception of right-clicking (I was clicking in the margin to set the breakpoint), yes, that is exactly what I did.|||Do you have any SQL Server service packs applied?|||How would I tell?|||

JWardRogers wrote:

How would I tell?

In BIDS, go to Help->About and select SSIS. What is the version number reported there?|||9.00.1399.00|||That's the original.

Try grabbing the SQL Server Service Pack 2 and installing that. Many fixes are contained in SP1 and SP2 as well.|||

Phil Brammer wrote:

That's the original.

Try grabbing the SQL Server Service Pack 2 and installing that. Many fixes are contained in SP1 and SP2 as well.

But unfortunately not the fix for my problem. :-(

SP2 is installed and it is still behaving the same way.

Version is now 9.00.3042.00

|||

I'm still having the same problem...

|||XP? Vista?|||

Server 2003 version 5.2.3790 (service pack 1.0)

Hot Fix: KB931836

4GB RAM

|||

JWardRogers wrote:

Server 2003 version 5.2.3790 (service pack 1.0)

Hot Fix: KB931836

4GB RAM

Do you also develop on a local workstation? Have you tried breakpoints on that if so?

Script Task scripts will not stop at breakpoints.

I can not debug any of my scripts. They execute just fine, but if I have a breakpoint set in the script code (in VSA), I get the message:

SQL server integration services script task has encountered a problem and needs to close. We are sorry for the inconvenience.

If you were in the middle of something, the information you were working on might be lost.

Debug Close

When I choose "Close" I get this:

sMicrosoft Visual Studio for Applications has lost the link to .

Your work will be exported to <<my Local Settings My Documents path>> when you quit the application.

OK

When I click "OK" my package executes normally, but no breakpoints will fire from that point on.

No need to post your message twice....

Script Tasks, not Script Components, correct?

One workaround is to use a MSGBOX().|||I was in the process of deleting my other post when you replied. I didn't want to post in a thread that had something marked as an answer. Yes, this is for script tasks. I certainly could use MsgBox() but that is hardly an answer to this problem. I could also write text out to a file, call a web service, insert a record into a table, etc. None of those things take the place of stepping through code. Is there a fix in the works for this issue? It really makes script tasks of limited use, or at least it makes them take much longer to develop.|||And you are following these steps?

http://technet.microsoft.com/en-us/library/ms140033.aspx|||With the exception of right-clicking (I was clicking in the margin to set the breakpoint), yes, that is exactly what I did.|||Do you have any SQL Server service packs applied?|||How would I tell?|||

JWardRogers wrote:

How would I tell?

In BIDS, go to Help->About and select SSIS. What is the version number reported there?|||9.00.1399.00|||That's the original.

Try grabbing the SQL Server Service Pack 2 and installing that. Many fixes are contained in SP1 and SP2 as well.|||

Phil Brammer wrote:

That's the original.

Try grabbing the SQL Server Service Pack 2 and installing that. Many fixes are contained in SP1 and SP2 as well.

But unfortunately not the fix for my problem. :-(

SP2 is installed and it is still behaving the same way.

Version is now 9.00.3042.00

|||

I'm still having the same problem...

|||XP? Vista?|||

Server 2003 version 5.2.3790 (service pack 1.0)

Hot Fix: KB931836

4GB RAM

|||

JWardRogers wrote:

Server 2003 version 5.2.3790 (service pack 1.0)

Hot Fix: KB931836

4GB RAM

Do you also develop on a local workstation? Have you tried breakpoints on that if so?

Script Task Error --Object reference not set to an instance of an object

I am trying to execute this code feom Script task while excuting its giving me error that "Object reference not set to an instance of an object." The assemblies Iam referening in this code are there in GAC. Any idea abt this.

Thanks,

PublicSub Main()

Dim remoteUri AsString

Dim fireAgain AsBoolean

Dim uriVarName AsString

Dim fileVarName AsString

Dim httpConnection As Microsoft.SqlServer.Dts.Runtime.HttpClientConnection

Dim emptyBytes(0) AsByte

Dim SessionID AsString

Dim CusAuth As CustomAuth

Try

' Determine the correct variables to read for URI and filename

uriVarName = "vsReportUri"

fileVarName = "vsReportDownloadFilename"

' create SessionID for use with HD Custom authentication

CusAuth = New CustomAuth(ASCIIEncoding.ASCII.GetBytes(Dts.Variables("in_vsBatchKey").Value.ToString()))

Dts.Variables(uriVarName).Value = Dts.Variables(uriVarName).Value.ToString() + "&" + _

"BeginDate=" + Dts.Variables("in_vsBeginDate").Value.ToString() + "&" + _

"EndDate=" + Dts.Variables("in_vsEndDate").Value.ToString()

Dim request As HttpWebRequest = CType(WebRequest.Create(Dts.Variables(uriVarName).Value.ToString()), HttpWebRequest)

'Set credentials based on the credentials found in the variables

request.Credentials = New NetworkCredential(Dts.Variables("in_vsReportUsername").Value.ToString(), _

Dts.Variables("in_vsReportPassword").Value.ToString(), _

Dts.Variables("in_vsReportDomain").Value.ToString())

'Place the custom authentication session ID in a cookie called BatchSession

request.CookieContainer.Add(New Cookie("BatchSession", CusAuth.GenerateSession("EmailAlertingSSIS"), "/", Dts.Variables("in_vsReportDomain").Value.ToString()))

' Set some reasonable limits on resources used by this request

request.MaximumAutomaticRedirections = 4

request.MaximumResponseHeadersLength = 4

' Prepare to download, write messages indicating download start

Dts.Events.FireInformation(0, String.Empty, String.Format("Downloading '{0}' from '{1}'", _

Dts.Variables(fileVarName).Value.ToString(), Dts.Variables(uriVarName).Value.ToString()), String.Empty, 0, fireAgain)

Dts.Log(String.Format("Downloading '{0}' from '{1}'", Dts.Variables(fileVarName).Value.ToString(), Dts.Variables(uriVarName).Value.ToString()), 0, emptyBytes)

' Download data

Dim response As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse)

' Get the stream associated with the response.

Dim receiveStream As Stream = response.GetResponseStream()

' Pipes the stream to a higher level stream reader with the required encoding format.

Dim readStream AsNew StreamReader(receiveStream, Encoding.UTF8)

Dim fileStream AsNew StreamWriter(Dts.Variables(fileVarName).Value.ToString())

fileStream.Write(readStream.ReadToEnd())

fileStream.Flush()

fileStream.Close()

readStream.Close()

fileStream.Dispose()

readStream.Dispose()

'Download the file and report success

Dts.TaskResult = Dts.Results.Success

Catch ex As Exception

' post the error message we got back.

Dts.Events.FireError(0, String.Empty, ex.Message, String.Empty, 0)

Dts.TaskResult = Dts.Results.Failure

EndTry

EndSub

It isn't clear what is failing, a line number or similar would help. Since you mention external assemblies, have you read this -

Referencing Other Assemblies in Scripting Solutions
(http://msdn2.microsoft.com/en-us/library/9b655bcd-19f6-43d8-9f89-1b4d299c6380.aspx)

Friday, March 9, 2012

Script execution problem

When I try to execute my script using the rs command i canâ't
Generally I use to type:
rs â's http://myServer/reporrserver ; â'i myScript.rss
but they are some predefined values that donâ't allow me to execute my
command because it tries to look for the server:
http://http://myServer/reporrserver/reporrservices
if I change it like this
rs â's myServer â'i myScript.rss
it also does not works because it interpreted it like
http://myServer/reporrservices
Where can I change this default values'I have the same problem in one more server. I donâ't know if it has something
to do. But In the server was the SP1_en and over it I stalled a SP1_de. It
always have the same problem:
Could not connect to server: http://my_server/ReportService.asmx
"Soan" wrote:
> When I try to execute my script using the rs command i canâ't
> Generally I use to type:
> rs â's http://myServer/reporrserver ; â'i myScript.rss
> but they are some predefined values that donâ't allow me to execute my
> command because it tries to look for the server:
> http://http://myServer/reporrserver/reporrservices
> if I change it like this
> rs â's myServer â'i myScript.rss
> it also does not works because it interpreted it like
> http://myServer/reporrservices
> Where can I change this default values'
>

Saturday, February 25, 2012

Scorecard A SQL

I am looking for a method to measure SQL performance. For example:
1. execute a SQL first
2. immediately I issue a sql command command which will capture the CPU, IO
and memory used by the SQL commnad which I issued in step 1.
See Profiler in BOL.
"Josephine" <Josephine@.discussions.microsoft.com> wrote in message
news:946E50BF-FA5D-43F6-8D1B-535366F1B1F5@.microsoft.com...
> I am looking for a method to measure SQL performance. For example:
> 1. execute a SQL first
> 2. immediately I issue a sql command command which will capture the CPU,
IO
> and memory used by the SQL commnad which I issued in step 1.
|||Answered in .programming -- please refrain from multi-posting.
Adam Machanic
SQL Server MVP
http://www.sqljunkies.com/weblog/amachanic
"Josephine" <Josephine@.discussions.microsoft.com> wrote in message
news:946E50BF-FA5D-43F6-8D1B-535366F1B1F5@.microsoft.com...
> I am looking for a method to measure SQL performance. For example:
> 1. execute a SQL first
> 2. immediately I issue a sql command command which will capture the CPU,
IO
> and memory used by the SQL commnad which I issued in step 1.

Scorecard A SQL

I am looking for a method to measure SQL performance. For example:
1. execute a SQL first
2. immediately I issue a sql command command which will capture the CPU, IO
and memory used by the SQL commnad which I issued in step 1.See Profiler in BOL.
"Josephine" <Josephine@.discussions.microsoft.com> wrote in message
news:946E50BF-FA5D-43F6-8D1B-535366F1B1F5@.microsoft.com...
> I am looking for a method to measure SQL performance. For example:
> 1. execute a SQL first
> 2. immediately I issue a sql command command which will capture the CPU,
IO
> and memory used by the SQL commnad which I issued in step 1.|||Answered in .programming -- please refrain from multi-posting.
Adam Machanic
SQL Server MVP
http://www.sqljunkies.com/weblog/amachanic
--
"Josephine" <Josephine@.discussions.microsoft.com> wrote in message
news:946E50BF-FA5D-43F6-8D1B-535366F1B1F5@.microsoft.com...
> I am looking for a method to measure SQL performance. For example:
> 1. execute a SQL first
> 2. immediately I issue a sql command command which will capture the CPU,
IO
> and memory used by the SQL commnad which I issued in step 1.

Scorecard A SQL

I am looking for a method to measure SQL performance. For example:
1. execute a SQL first
2. immediately I issue a sql command command which will capture the CPU, IO
and memory used by the SQL commnad which I issued in step 1.See Profiler in BOL.
"Josephine" <Josephine@.discussions.microsoft.com> wrote in message
news:946E50BF-FA5D-43F6-8D1B-535366F1B1F5@.microsoft.com...
> I am looking for a method to measure SQL performance. For example:
> 1. execute a SQL first
> 2. immediately I issue a sql command command which will capture the CPU,
IO
> and memory used by the SQL commnad which I issued in step 1.|||Answered in .programming -- please refrain from multi-posting.
--
Adam Machanic
SQL Server MVP
http://www.sqljunkies.com/weblog/amachanic
--
"Josephine" <Josephine@.discussions.microsoft.com> wrote in message
news:946E50BF-FA5D-43F6-8D1B-535366F1B1F5@.microsoft.com...
> I am looking for a method to measure SQL performance. For example:
> 1. execute a SQL first
> 2. immediately I issue a sql command command which will capture the CPU,
IO
> and memory used by the SQL commnad which I issued in step 1.