Copy databases from One SQL instance to another -dbatools

Back with another quick tip to copy databases from one sql instance to another using dbatools one-line command script:

Copy-DbaDatabase -Source SQLSERVER01 -Destination SQLSERVER02 -Database STAGE_DB_Name -BackupRestore -SharedPath \\NetworkPath\SQLBackup\SQLSERVER01 -NewName PROD_DB_Name

-Source: Name of the source SQL server

-Destination: Name of the destination SQL server where you are going to restore the source DB

-BackupRestore: Will use a backup and restore methodology to copy over the database

-SharedPath: This network path should be accessible to both source and destination servers

-NewName: Use this if you want to restore the database with a different name from source

SQL Server 2017 to 2019 Upgrade – Error and lesson learned

When I was upgrading my SQL Server 2017 instance to SQL Server 2019 from a mounted ISO file, I encountered an error message during the upgrade process, “An error occurred for a dependency of the feature causing the setup process for the feature to fail.”. You can see the error in the illustration below.

At first, it was not clear what the cause of this error was. First, I looked at the summary log by clicking on the hyperlink provided by the above window to look for more information. Scrolling down in the log, I found several errors related to failed components:

After some google search, it seems to be some sort of bug with SQL 2019 setup and issue is related to pre-installed SSMS.

However, in the end, it turned out to be an issue with the SQL Server Management Studio (SSMS) versions 18.0, 18.1, 18.2 and 18.3, if they were preinstalled on the server before attempting to install SQL Server 2019.


What worked for me was taking the content of the mounted SQL Server 2019 ISO file and copying it to a local drive. After this, I restarted the installation ,and it worked without any problems.

This was found in Microsoft documentation:

We have below workarounds:

  • On existing machines, where SSMS 18.3 or lower is already installed.
    • Uninstall SQL Server 2012 Native Client which got installed with SSMS. Then install SQL Server 2019. OR
    • Instead of running setup from mounted ISO, copy the content of media to a local drive or a network share and start setup.exe from those locations.
  • On new machines, where SSMS is NOT installed.
    • First install SQL Server 2019 and then install SSMS 18.3 OR
    • Install version of SSMS greater than 18.3.1 and then install SQL Server 2019

One query many plans – SQL Server

When you see this happening in your system. Here is the script that uses system DMVs to look at the cache for execution plans:

planobj.pages_in_bytes / 1024 AS [PlanKB],
FROM sys.dm_exec_cached_plans cplan
OUTER APPLY sys.dm_exec_sql_test(cplan.[plan_handle] sqltxt
OUTER APPLY sys.dm_exec_query_pla(cplan.[plan_handle] qrypln
INNER JOIN sys.dm_os_memory_ibjects planobj
ON planobj.memory_object_address = cplan.memory_object_address
WHERE cplan.parent_plan_handle is NULL
AND cplan.cacheobjtype IN (N'Compiled Plan',N'Compiled Plan Stub')
ORDER BY cplan.objtype, cplan.plan_handle;

You see the many plans scenario when dynamic SQL is being generated by ORM. It would help if you can convert functions or queries into a stored procedure so that fewer plans get cached into the system and get re-used.

%d bloggers like this: