Showing posts with label role. Show all posts
Showing posts with label role. Show all posts

Friday, March 30, 2012

How to script Role Memebers

Is there any way to script Databse Role(s) and Role Memeber(s) using SQL-SMO?

The workaround i am using here is, set the server connection execution mode to CaptureSQL and and use AddMemeber method while looping through Server.Database.Roles.EnumMemebers. This creates a string collection of sp_addrolemembers. (let me know if someone wants to have a look at this code)

I couldn't even figureout how to do this using SQL Server Management Studion. When i script the entire database using SQL Server Mangement Studio, i dont see sp_addrolemember statements.

Am I missing something?

Try something like this:

Dim scrDBScript As Scripter
Dim objSMOObjects(100) As SqlSmoObject
Dim intObjCount As Integer
intObjCount = 0

Dim srv As Server
Dim srvConn As ServerConnection
srv = New Server("MyServer")
srvConn = srv.ConnectionContext
srvConn.LoginSecure = True

Dim db As Database
Dim objRoles As DatabaseRoleCollection
Dim objRole As DatabaseRole

db = srv.Databases("AdventureWorks")
objRoles = db.Roles
For Each objRole In objRoles
objSMOObjects(intObjCount) = objRole
intObjCount += 1
Next

scrDBScript = New Scripter(srv)
scrDBScript.Options.FileName = "c:\DBScript.sql"
scrDBScript.Options.IncludeHeaders = True
scrDBScript.Options.AppendToFile = True

ReDim Preserve objSMOObjects(intObjCount - 1)
scrDBScript.Script(objSMOObjects)

This code will create a script of each role defined in the AdventureWorks database. Hope that helps.

|||

Allen, Thanks for replying on this! However, this code only genrates sp_addrole statements. What I am looking for is to script rolememebers (sp_addrolememeber).

Any thoughts?

|||

Not sure if this works, but if it doesn't I think you'll get the idea:

db = srv.Databases("AdventureWorks")
objRoles = db.Roles
For Each objRole In objRoles
Dim colMembers As System.Collections.Specialized.StringCollection
Dim strMember As String
colMembers = objRole.EnumMembers
For Each strMember In colMembers
objSMOObjects(intObjCount) = objRole
intObjCount += 1
Next
Next

The EnumMembers method of the DatabaseRole object returns a string collection with the members of the role in the collection.

How to script existing database role WITH securables?

Hello!

Please, help with the subject. SMO generates only this:

USE [DB1]

GO

/****** Object: DatabaseRole [VIP_RDR] Script Date: 05/28/2007 03:48:05 ******/

CREATE ROLE [VIP_RDR] AUTHORIZATION [dbo]

Securables are not included for some reason.

Thank you.

Well, SMO does not do that.

So - "manually", using GRANT (together with select from sys.objects if you can distinct database objects using select clause)

Good luck!

sql

How to script existing database role WITH securables?

Hello!

Please, help with the subject. SMO generates only this:

USE [DB1]

GO

/****** Object: DatabaseRole [VIP_RDR] Script Date: 05/28/2007 03:48:05 ******/

CREATEROLE [VIP_RDR] AUTHORIZATION [dbo]

Securables are not included for some reason.

Thank you.

Well, SMO does not do that.

So - "manually", using GRANT (together with select from sys.objects if you can distinct database objects using select clause)

Good luck!

Wednesday, March 21, 2012

How to Run Job without Sysadmin Role

Hi All,
I know this question have already posted frequently, and I've tried all
the solution that they're suggested, but still doesn't work. I've
changed job owner and also setup the SQL Server Proxy account and
password into that Non-SyAdmin user, but still failed when run the job.
Is there any other solution? Please help me...
ThanksWhat error are you getting when the job fails?
-Sue
On 9 Nov 2005 18:13:06 -0800, resant_v@.yahoo.com wrote:

>Hi All,
>I know this question have already posted frequently, and I've tried all
>the solution that they're suggested, but still doesn't work. I've
>changed job owner and also setup the SQL Server Proxy account and
>password into that Non-SyAdmin user, but still failed when run the job.
>Is there any other solution? Please help me...
>
>Thanks|||"Non-SysAdmins have been denied permission to run CmdExec job steps"
But never mind, i've solved now but i'm getting new error :
"The specified @.job_name (Name of Job) doesn't exist".
This happen when I changed job owner into sysadmin user not that
Non-Sysadmin user.
Oh yeah, I use sysadmin user for proxy account, so when a Non-Sysadmin
user run the job, they will use the proxy account, right?
So, what should I do now?
Thanks

How to run a xmla script from an SSIS package

I have a xmla script that adds an role to a SQL Server 2005 Analysis Service
s
database (see below). How do I run that from an SSIS package ? Is there a
specific SSIS task that will do it ?
Here's the script:
<Create xmlns="http://schemas.microsoft.com/analysisservices/2003/engine">
<ParentObject>
<DatabaseID>Ask</DatabaseID>
</ParentObject>
<ObjectDefinition>
<Role xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ID>Role</ID>
<Name>REDPEPPER</Name>
<Members>
<Member>
<Name>Everyone</Name>
</Member>
</Members>
</Role>
</ObjectDefinition>
</Create>
Thanks,
CraigHello CraigHB,
There is an "Analysis Services Execute DDL" task which should do the trick
Darren Gosbell - SQL Server MVP
blog: http://geekswithblogs.net/darrengosbell

> I have a xmla script that adds an role to a SQL Server 2005 Analysis
> Services database (see below). How do I run that from an SSIS package
> ? Is there a specific SSIS task that will do it ?
> Here's the script: <Create
> xmlns="http://schemas.microsoft.com/analysisservices/2003/engine">
> <ParentObject> <DatabaseID>Ask</DatabaseID> </ParentObject>
> <ObjectDefinition> <Role xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <ID>Role</ID>
> <Name>REDPEPPER</Name> <Members> <Member> <Name>Everyone</Name>
> </Member> </Members> </Role> </ObjectDefinition> </Create>
> Thanks, Craig
>

How to run a xmla script from an SSIS package

I have a xmla script that adds an role to a SQL Server 2005 Analysis Services
database (see below). How do I run that from an SSIS package ? Is there a
specific SSIS task that will do it ?
Here's the script:
<Create xmlns="http://schemas.microsoft.com/analysisservices/2003/engine">
<ParentObject>
<DatabaseID>Ask</DatabaseID>
</ParentObject>
<ObjectDefinition>
<Role xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ID>Role</ID>
<Name>REDPEPPER</Name>
<Members>
<Member>
<Name>Everyone</Name>
</Member>
</Members>
</Role>
</ObjectDefinition>
</Create>
Thanks,
Craig
Hello CraigHB,
There is an "Analysis Services Execute DDL" task which should do the trick
Darren Gosbell - SQL Server MVP
blog: http://geekswithblogs.net/darrengosbell

> I have a xmla script that adds an role to a SQL Server 2005 Analysis
> Services database (see below). How do I run that from an SSIS package
> ? Is there a specific SSIS task that will do it ?
> Here's the script: <Create
> xmlns="http://schemas.microsoft.com/analysisservices/2003/engine">
> <ParentObject> <DatabaseID>Ask</DatabaseID> </ParentObject>
> <ObjectDefinition> <Role xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <ID>Role</ID>
> <Name>REDPEPPER</Name> <Members> <Member> <Name>Everyone</Name>
> </Member> </Members> </Role> </ObjectDefinition> </Create>
> Thanks, Craig
>
sql

Monday, March 19, 2012

How to revoke write, update access from public role

Hi,
I have an application that gives all the write, update access to public role
, how could I quickly revoke all the Write and Update access from Public, in
stead of uncheck all the checked boxes?
Thanks.Hi
Execute the following in Query Analyzer with text result (Query menu click
result in text) and copy and paste results
to give you the required script.
select 'revoke all on ' + QUOTENAME(name) + ' from [public]'
from sysobjects where type in('U','P','V','TR','IF','FN')
and objectproperty(id,'IsMSShipped')=0
go
Tahnks
Hari
MCDBA
"Hong" <anonymous@.discussions.microsoft.com> wrote in message
news:41AE885E-A0CB-4542-B6A9-843454B33A66@.microsoft.com...
> Hi,
> I have an application that gives all the write, update access to public
role, how could I quickly revoke all the Write and Update access from
Public, instead of uncheck all the checked boxes?
> Thanks.