Alternative way to determine DB user when using MSSQL |
Top Previous Next | Direct link to this topic |
The easiest way to determine database user for a SAP B1 company database is checking the SLD using the method described in the topic "Before add-on installation". But if that is not an option and the SAP B1 server is running on MSSQL then here is the following two alternatives:
Alternative 11.Open Microsoft SQL Server Management Studio. 2.Go to Security. 3.Go to Logins. 4.Go through each of the logins that start with B1_ and ends with _RW and one by one do the following: a.Right click and select properties. b.Go to User Mapping c.Check which database that the login is mapped to. If it is mapped to a SAP B1 company database, then this is the SAP B1 database user for that database.
For example, the login in the image below is the database user for a SBODemoDK database:
Alternative 2Run the following query on the database server with a login that has access to all databases (such as the sa login):
DECLARE @DBRolePermissions TABLE( DatabaseName varchar(300), Principal_Name sysname, Login_Name sysname NULL, DB_RoleMember varchar(300), Permission_Type sysname)
INSERT INTO @DBRolePermissions EXEC sp_MSforeachdb ' SELECT DISTINCT ''?'', users.Name, suser_sname(users.sid), roles.Name, roles.type_desc FROM [?].sys.database_role_members r LEFT OUTER JOIN [?].sys.database_principals users on r.member_principal_id = users.principal_id LEFT OUTER JOIN [?].sys.database_principals roles on r.role_principal_id = roles.principal_id'
INSERT INTO @DBRolePermissions EXEC sp_msforeachdb ' SELECT DISTINCT ''?'', users.Name, suser_sname(users.sid), r.Permission_Name, r.class_desc FROM [?].sys.database_permissions r LEFT OUTER JOIN [?].sys.database_principals users on r.grantee_principal_id = users.principal_id WHERE r.class_desc = ''DATABASE'''
SELECT DISTINCT Principal_Name, Login_Name, DatabaseName, DB_RoleMember AS Permission_Name FROM @DBRolePermissions WHERE Permission_Type != 'DATABASE' AND principal_name LIKE '%_RW' AND DatabaseName != 'BOY-IC-COMMON' ORDER BY Principal_Name, DatabaseName, DB_RoleMember |