SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Connect Any Database equivalent for Pre-SQL2014. EnumMembers() failure.


Connect Any Database equivalent for Pre-SQL2014. EnumMembers() failure.

Author
Message
squaffle
squaffle
SSC Rookie
SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)

Group: General Forum Members
Points: 25 Visits: 22
Hi guys,
Thought this could lie in the Connecting, Powershell and SMO sections among others and decided to post here in case anyone had encountered the same problem.

I'm relatively new to SQL, and getting role members on database servers with an SMO and EnumMembers().
Everything works fine with my admin account but been trying to move to a service account and hitting problems. On my 2014 servers I have a serverlevel role I've created that's granting "Connect Any Database" to the service account, that allows it to connect to current and future databases. Haven't been able to see inside the created objects yet as errors out on my 2008r2 server with:

The server principal "serviceAccount" is not able to access the database "database" under the current security context. '. Process Exit Code -1. The step failed.

This I understand to be because it can't connect as has a server login but doesn't have a database login. Short of manually adding a login to each database or giving a high level of privilege any advice ? (Trying to keep the permissions I give to the service account as low as possible)

For anyone who might be interested, a portion of my code:

$databaseList = $svrConnection.Databases | WHERE {$_.IsSystemObject -eq $false}
foreach ($db in $databaseList)
{
$dbRolesList = $db.Roles # get roles for the database
foreach ($dbRole in $dbRolesList)
{
#Get all role members and process them
$roleN = $dbRole.Name
$dbRoleMemberList = $dbrole.EnumMembers()
if($dbRoleMemberList)
{
Process-Members -listOfMembers $dbRoleMemberList -DatabaseName $db.Name -roleName $roleN
}
}
}


Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum








































































































































































SQLServerCentral


Search