Showing posts with label Migration. Show all posts
Showing posts with label Migration. Show all posts

Sunday, November 23, 2014

Move Master & Resource databases in SQL Server 2005

Move Master & Resource databases in SQL Server 2005
The Resource database depends on the location of the master database. The Resource data and log files must reside together and must be in the same location as the master data file (master.mdf). Therefore, if you move the master database, you must also move the Resource database to the same location as the master data file. Do not put the Resource database in either compressed or encrypted NTFS file system folders. Doing so will hinder performance and prevent upgrades. To move the master and Resource databases, follow these steps.
From the Start menu, point to All Programs, point to Microsoft SQL Server 2005, point to Configuration Tools, and then click SQL Server Configuration Manager.
In the SQL Server 2005 Services node, right-click the instance of SQL Server (for example, SQL Server (MSSQLSERVER)) and choose Properties.
In the SQL Server (instance_name) Properties dialog box, click the Advanced tab.
Edit the Startup Parameters values to point to the planned location for the master database data and log files, and click OK. Moving the error log file is optional.
The parameter value for the data file must follow the -d parameter and the value for the log file must follow the -l parameter. The following example shows the parameter values for the default location of the master data and log files.
-dC:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\master.mdf;-eC:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\LOG\ERRORLOG;-lC:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\mastlog.ldf
If the planned relocation for the master data and log files is E:\SQLData, the parameter values would be changed as follows:
-dE:\SQLData\master.mdf;-eC:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\LOG\ERRORLOG;-lE:\SQLData\mastlog.ldf
Stop the instance of SQL Server by right-clicking the instance name and choosing Stop.
Move the master.mdf and mastlog.ldf files to the new location.
Start the instance of SQL Server in master-only recovery mode by entering one of the following commands at the command prompt. The parameters specified in these commands are case sensitive. The commands fail when the parameters are not specified as shown.
For the default (MSSQLSERVER) instance, run the following command.
NET START MSSQLSERVER /f /T3608
For a named instance, run the following command.
NET START MSSQL$instancename /f /T3608
Using sqlcmd commands or SQL Server Management Studio, run the following statements. Change the FILENAME path to match the new location of the master data file. Do not change the name of the database or the file names.
ALTER DATABASE mssqlsystemresource
    MODIFY FILE (NAME=data, FILENAME= 'new_path_of_master\mssqlsystemresource.mdf');
GO
ALTER DATABASE mssqlsystemresource
    MODIFY FILE (NAME=log, FILENAME= 'new_path_of_master\mssqlsystemresource.ldf');
GO
Move the mssqlsystemresource.mdf and mssqlsystemresource.ldf files to the new location.
Set the Resource database to read-only by running the following statement.
ALTER DATABASE mssqlsystemresource SET READ_ONLY;
Exit the sqlcmd utility or SQL Server Management Studio.
Stop the instance of SQL Server.
Restart the instance of SQL Server.
Verify the file change for the master database by running the following query. The Resource database metadata cannot be viewed by using the system catalog views or system tables.
SELECT name, physical_name AS CurrentLocation, state_desc
FROM sys.master_files
WHERE database_id = DB_ID('master');
GO
Moving the tempdb database
tempdb is re-created each time the instance of SQL Server is started, you do not have to physically move the data and log files. The files are created in the new location when the service is restarted in step 3. Until the service is restarted, tempdb continues to use the data and log files in existing location.
Determine the logical file names of the tempdb database and their current location on the disk.
SELECT name, physical_name AS CurrentLocation
FROM sys.master_files
WHERE database_id = DB_ID(N'tempdb');
GO
Change the location of each file by using ALTER DATABASE.
USE master;
GO
ALTER DATABASE tempdb
MODIFY FILE (NAME = tempdev, FILENAME = 'E:\SQLData\tempdb.mdf');
GO
ALTER DATABASE tempdb
MODIFY FILE (NAME = templog, FILENAME = 'F:\SQLLog\templog.ldf');
GO
Stop and restart the instance of SQL Server.
Verify the file change.
SELECT name, physical_name AS CurrentLocation, state_desc
FROM sys.master_files
WHERE database_id = DB_ID(N'tempdb');
Delete the tempdb.mdf and templog.ldf files from the original location.

Friday, July 11, 2014

Scripting Server Permissions And Role Assignments


SET NOCOUNT ON

SELECT  
'USE' SPACE(1) + QUOTENAME('MASTER'AS '--Database Context'

-- Role Members 

SELECT  'EXEC sp_addsrvrolemember @rolename =' SPACE(1)
        + 
QUOTENAME(usr1.name'''') + ', @loginame =' SPACE(1)
        + 
QUOTENAME(usr2.name''''AS '--Role Memberships' FROM    sys.server_principals AS usr1
        
INNER JOIN sys.server_role_members AS rm ON usr1.principal_id rm.role_principal_id
        
INNER JOIN sys.server_principals AS usr2 ON rm.member_principal_id usr2.principal_id ORDER BY rm.role_principal_id ASC

-- Permissions 

SELECT  server_permissions.state_desc COLLATE SQL_Latin1_General_CP1_CI_AS
        
' ' server_permissions.permission_name COLLATE SQL_Latin1_General_CP1_CI_AS
        
' TO [' server_principals.name COLLATE SQL_Latin1_General_CP1_CI_AS
        
']' AS '--Server Level Permissions' FROM    sys.server_permissions AS server_permissions WITH NOLOCK )
        
INNER JOIN sys.server_principals AS server_principals WITH NOLOCK ONserver_permissions.grantee_principal_id server_principals.principal_id WHERE   server_principals.type IN 'S''U''G' ORDER BY server_principals.name,
        
server_permissions.state_desc,
        
server_permissions.permission_name 

Cannot access the specified path or file on the server. Verify that you have the necessary security privileges and that the path or file exists

If you received below error while attaching a .mdf file in cluster environment please follow below steps to resolve the issue ERROR Ca...