Skip to content

Commit c04d867

Browse files
authored
Merge pull request #221873 from ajithkr-ms/main
Documenting minimal set of permissions required for SQL assessment
2 parents 0158beb + 5ec3a96 commit c04d867

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

articles/migrate/how-to-discover-applications.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ The software inventory is exported and downloaded in Excel format. The **Softwar
7272
> [!NOTE]
7373
> Appliance can connect to only those SQL Server instances to which it has network line of sight, whereas software inventory by itself may not need network line of sight.
7474
75+
[!INCLUDE [Minimal Permissions for SQL Assessment](../../includes/database-migration-service-sql-permissions.md)]
76+
7577
Once connected, appliance gathers configuration and performance data of SQL Server instances and databases. The SQL Server configuration data is updated once every 24 hours and the performance data are captured every 30 seconds. Hence any change to the properties of the SQL Server instance and databases such as database status, compatibility level etc. can take up to 24 hours to update on the portal.
7678

7779
## Discover ASP.NET web apps
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
---
2+
author: ajithkr-ms
3+
ms.service: sql-database
4+
ms.topic: include
5+
ms.date: 12/19/2022
6+
ms.author: ajithkr-ms
7+
---
8+
9+
The login used to connect to a source SQL Server instance requires certain minimal permissions to query the requisite information. The following script shows creation of a SQL Server login with the requisite permissions.
10+
11+
```sql
12+
-- Create a login to run the assessment
13+
use master;
14+
CREATE LOGIN [evaluator]
15+
WITH PASSWORD = '<provide a strong password>'
16+
GO
17+
18+
-- Create user in every database other than tempdb and model and provide minimal read-only permissions.
19+
use master;
20+
EXECUTE sp_MSforeachdb 'USE [?]; IF (''?'' NOT IN (''tempdb'',''model'')) CREATE USER [evaluator] FOR LOGIN [evaluator]'
21+
EXECUTE sp_MSforeachdb 'USE [?]; IF (''?'' NOT IN (''tempdb'',''model'')) GRANT SELECT ON sys.sql_expression_dependencies TO [evaluator]'
22+
EXECUTE sp_MSforeachdb 'USE [?]; IF (''?'' NOT IN (''tempdb'',''model'')) GRANT VIEW DATABASE STATE TO [evaluator]'
23+
GO
24+
25+
-- Provide server level read-only permissions
26+
use master;
27+
GRANT SELECT ON sys.sql_expression_dependencies TO [evaluator]
28+
GRANT EXECUTE ON OBJECT::sys.xp_regenumkeys TO [evaluator];
29+
GRANT VIEW DATABASE STATE TO evaluator
30+
GRANT VIEW SERVER STATE TO evaluator
31+
GRANT VIEW ANY DEFINITION TO evaluator
32+
GO
33+
34+
-- Required from SQL 2014 onwards for database connectivity.
35+
use master;
36+
GRANT CONNECT ANY DATABASE TO evaluator
37+
GO
38+
39+
-- Provide msdb specific permissions
40+
use msdb;
41+
GRANT EXECUTE ON [msdb].[dbo].[agent_datetime] TO [evaluator]
42+
GRANT SELECT ON [msdb].[dbo].[sysjobsteps] TO [evaluator]
43+
GRANT SELECT ON [msdb].[dbo].[syssubsystems] TO [evaluator]
44+
GRANT SELECT ON [msdb].[dbo].[sysjobhistory] TO [evaluator]
45+
GRANT SELECT ON [msdb].[dbo].[syscategories] TO [evaluator]
46+
GRANT SELECT ON [msdb].[dbo].[sysjobs] TO [evaluator]
47+
GRANT SELECT ON [msdb].[dbo].[sysmaintplan_plans] TO [evaluator]
48+
GRANT SELECT ON [msdb].[dbo].[syscollector_collection_sets] TO [evaluator]
49+
GRANT SELECT ON [msdb].[dbo].[sysmail_profile] TO [evaluator]
50+
GRANT SELECT ON [msdb].[dbo].[sysmail_profileaccount] TO [evaluator]
51+
GRANT SELECT ON [msdb].[dbo].[sysmail_account] TO [evaluator]
52+
GO
53+
54+
-- Clean up
55+
--use master;
56+
-- EXECUTE sp_MSforeachdb 'USE [?]; DROP USER [evaluator]'
57+
-- DROP LOGIN [evaluator]
58+
--GO
59+
```
60+
61+
Here's how the permissions script can be used:
62+
63+
- Save the permissions script (with valid password string) as an _.sql_ file, say _c:\workspace\MinPermissions.sql_
64+
- Connect to the instance(s) using an account with sysadmin permissions and execute the script. You can use **SQL Server Management Studio** or **sqlcmd**. The following example uses a trusted connection.
65+
```cmd
66+
sqlcmd.exe -S sourceserver\sourceinstance -d master -E -i c:\workspace\MinPermissions.sql
67+
```
68+
- Use the minimal permissions account so created for further connections.
69+

0 commit comments

Comments
 (0)