Charles Okwuagwu
Charles Okwuagwu

Reputation: 10866

SQL Server 2016 Copy Database wizard error

I'm trying to copy a SQL Server Database from sql server 2016 dev edition to SQL Server 2014 dev edition.

It fails with the following log:

#Fields: event,computer,operator,source,sourceid,executionid,starttime,endtime,datacode,databytes,message

OnInformation,PAPERLESS-PRIME,NT AUTHORITY\NETWORK SERVICE,PAPERLESS-PRIME_PAPERLESS-PRIME_SQLEXPRESS_Transfer Objects Task,{F858F211-3783-40F8-9C7A-B477576706D4},{AB42BFE8-D674-4E86-ACEA-FA89BFF7E8BE},8/8/2016 11:40:52 AM,8/8/2016 11:40:52 AM,0,0x,Transferring database callmanager_pwc from PAPERLESS-PRIME server as callmanager_pwc to PAPERLESS-PRIME\SQLEXPRESS server
OnInformation,PAPERLESS-PRIME,NT AUTHORITY\NETWORK SERVICE,CDW_PAPERLESS-PRIME_PAPERLESS-PRIME_SQLEXPRESS_2,{2BE0FC74-D66D-4AFE-895F-B0CC80E7C848},{AB42BFE8-D674-4E86-ACEA-FA89BFF7E8BE},8/8/2016 11:40:52 AM,8/8/2016 11:40:52 AM,0,0x,Transferring database callmanager_pwc from PAPERLESS-PRIME server as callmanager_pwc to PAPERLESS-PRIME\SQLEXPRESS server
OnInformation,PAPERLESS-PRIME,NT AUTHORITY\NETWORK SERVICE,PAPERLESS-PRIME_PAPERLESS-PRIME_SQLEXPRESS_Transfer Objects Task,{F858F211-3783-40F8-9C7A-B477576706D4},{AB42BFE8-D674-4E86-ACEA-FA89BFF7E8BE},8/8/2016 11:40:52 AM,8/8/2016 11:40:52 AM,0,0x,Added data file callmanager in path C:\SQLDB\2014\callmanager_pwc.mdf to file group [PRIMARY]
OnInformation,PAPERLESS-PRIME,NT AUTHORITY\NETWORK SERVICE,CDW_PAPERLESS-PRIME_PAPERLESS-PRIME_SQLEXPRESS_2,{2BE0FC74-D66D-4AFE-895F-B0CC80E7C848},{AB42BFE8-D674-4E86-ACEA-FA89BFF7E8BE},8/8/2016 11:40:52 AM,8/8/2016 11:40:52 AM,0,0x,Added data file callmanager in path C:\SQLDB\2014\callmanager_pwc.mdf to file group [PRIMARY]
OnInformation,PAPERLESS-PRIME,NT AUTHORITY\NETWORK SERVICE,PAPERLESS-PRIME_PAPERLESS-PRIME_SQLEXPRESS_Transfer Objects Task,{F858F211-3783-40F8-9C7A-B477576706D4},{AB42BFE8-D674-4E86-ACEA-FA89BFF7E8BE},8/8/2016 11:40:52 AM,8/8/2016 11:40:52 AM,0,0x,Added log file callmanager_log in path C:\SQLDB\2014\callmanager_pwc.ldf
OnInformation,PAPERLESS-PRIME,NT AUTHORITY\NETWORK SERVICE,CDW_PAPERLESS-PRIME_PAPERLESS-PRIME_SQLEXPRESS_2,{2BE0FC74-D66D-4AFE-895F-B0CC80E7C848},{AB42BFE8-D674-4E86-ACEA-FA89BFF7E8BE},8/8/2016 11:40:52 AM,8/8/2016 11:40:52 AM,0,0x,Added log file callmanager_log in path C:\SQLDB\2014\callmanager_pwc.ldf
OnInformation,PAPERLESS-PRIME,NT AUTHORITY\NETWORK SERVICE,PAPERLESS-PRIME_PAPERLESS-PRIME_SQLEXPRESS_Transfer Objects Task,{F858F211-3783-40F8-9C7A-B477576706D4},{AB42BFE8-D674-4E86-ACEA-FA89BFF7E8BE},8/8/2016 11:40:52 AM,8/8/2016 11:40:52 AM,0,0x,Transferring data to database callmanager_pwc from callmanager_pwc
OnInformation,PAPERLESS-PRIME,NT AUTHORITY\NETWORK SERVICE,CDW_PAPERLESS-PRIME_PAPERLESS-PRIME_SQLEXPRESS_2,{2BE0FC74-D66D-4AFE-895F-B0CC80E7C848},{AB42BFE8-D674-4E86-ACEA-FA89BFF7E8BE},8/8/2016 11:40:52 AM,8/8/2016 11:40:52 AM,0,0x,Transferring data to database callmanager_pwc from callmanager_pwc
OnError,PAPERLESS-PRIME,NT AUTHORITY\NETWORK SERVICE,PAPERLESS-PRIME_PAPERLESS-PRIME_SQLEXPRESS_Transfer Objects Task,{F858F211-3783-40F8-9C7A-B477576706D4},{AB42BFE8-D674-4E86-ACEA-FA89BFF7E8BE},8/8/2016 11:40:54 AM,8/8/2016 11:40:54 AM,0,0x,Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
StackTrace:    at System.Collections.BitArray.Set(Int32 index, Boolean value)
   at Microsoft.SqlServer.Management.Smo.PermissionWorker.GetPermissionSetBase(PermissionEnumKind kind, Int32 i)
   at Microsoft.SqlServer.Management.Smo.SqlSmoObject.GetPermissionsFromCache(PermissionEnumKind kind)
   at Microsoft.SqlServer.Management.Smo.SqlSmoObject.AddScriptPermissions(StringCollection sc, PermissionEnumKind kind, ScriptingPreferences sp)
   at Microsoft.SqlServer.Management.Smo.ScriptMaker.ScriptCreateSpecialUrn(Urn urn, ScriptingPreferences sp, ObjectScriptingType& scriptType)
   at Microsoft.SqlServer.Management.Smo.ScriptMaker.ScriptCreate(Urn urn, ScriptingPreferences sp, ObjectScriptingType& scriptType)
   at Microsoft.SqlServer.Management.Smo.ScriptMaker.ScriptCreateObjects(IEnumerable`1 urns)
   at Microsoft.SqlServer.Management.Smo.ScriptMaker.ScriptUrns(List`1 orderedUrns)
   at Microsoft.SqlServer.Management.Smo.ScriptMaker.DiscoverOrderScript(IEnumerable`1 urns)
   at Microsoft.SqlServer.Management.Smo.ScriptMaker.ScriptWorker(List`1 urns, ISmoScriptWriter writer)
   at Microsoft.SqlServer.Management.Smo.DataTransferBase.GetScriptLoadedTransferWriter()
   at Microsoft.SqlServer.Management.Smo.Transfer.TransferData()
   at Microsoft.SqlServer.Dts.Tasks.TransferObjectsTask.TransferObjectsTask.TransferDatabasesUsingSMOTransfer()
OnError,PAPERLESS-PRIME,NT AUTHORITY\NETWORK SERVICE,CDW_PAPERLESS-PRIME_PAPERLESS-PRIME_SQLEXPRESS_2,{2BE0FC74-D66D-4AFE-895F-B0CC80E7C848},{AB42BFE8-D674-4E86-ACEA-FA89BFF7E8BE},8/8/2016 11:40:54 AM,8/8/2016 11:40:54 AM,0,0x,Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
StackTrace:    at System.Collections.BitArray.Set(Int32 index, Boolean value)
   at Microsoft.SqlServer.Management.Smo.PermissionWorker.GetPermissionSetBase(PermissionEnumKind kind, Int32 i)
   at Microsoft.SqlServer.Management.Smo.SqlSmoObject.GetPermissionsFromCache(PermissionEnumKind kind)
   at Microsoft.SqlServer.Management.Smo.SqlSmoObject.AddScriptPermissions(StringCollection sc, PermissionEnumKind kind, ScriptingPreferences sp)
   at Microsoft.SqlServer.Management.Smo.ScriptMaker.ScriptCreateSpecialUrn(Urn urn, ScriptingPreferences sp, ObjectScriptingType& scriptType)
   at Microsoft.SqlServer.Management.Smo.ScriptMaker.ScriptCreate(Urn urn, ScriptingPreferences sp, ObjectScriptingType& scriptType)
   at Microsoft.SqlServer.Management.Smo.ScriptMaker.ScriptCreateObjects(IEnumerable`1 urns)
   at Microsoft.SqlServer.Management.Smo.ScriptMaker.ScriptUrns(List`1 orderedUrns)
   at Microsoft.SqlServer.Management.Smo.ScriptMaker.DiscoverOrderScript(IEnumerable`1 urns)
   at Microsoft.SqlServer.Management.Smo.ScriptMaker.ScriptWorker(List`1 urns, ISmoScriptWriter writer)
   at Microsoft.SqlServer.Management.Smo.DataTransferBase.GetScriptLoadedTransferWriter()
   at Microsoft.SqlServer.Management.Smo.Transfer.TransferData()
   at Microsoft.SqlServer.Dts.Tasks.TransferObjectsTask.TransferObjectsTask.TransferDatabasesUsingSMOTransfer()
OnProgress,PAPERLESS-PRIME,NT AUTHORITY\NETWORK SERVICE,PAPERLESS-PRIME_PAPERLESS-PRIME_SQLEXPRESS_Transfer Objects Task,{F858F211-3783-40F8-9C7A-B477576706D4},{AB42BFE8-D674-4E86-ACEA-FA89BFF7E8BE},8/8/2016 11:40:55 AM,8/8/2016 11:40:55 AM,0,0x,Database transfer failed for 1 database(s).

Please is this an issue with the product, or is it something i'm doing wrong?

Upvotes: 3

Views: 789

Answers (2)

Maciej S.
Maciej S.

Reputation: 760

The only right way I know to achieve such goal is generating script from higher version of SQL Server and run it on lower version. To do it follow these steps:

  1. Open SQL Server Management Studio
  2. Right click on the database you are working with.
  3. Choose Tasks > Generate Scripts
  4. You will be presented with a wizard screen, on the introduction you can click next.
  5. Choose whether to script the entire database and objects or to select them individually. I like to leave it as the first option, everything. Click next
  6. In the output type, choose save scripts to a specific location
  7. Save to file
  8. Click on advanced
  9. Script for Server Version
  10. Choose the version you want, mine is 2012
  11. Types of data to script - Schema and data
  12. Leave the other settings as they were.
  13. Click on OK
  14. Files to generate - Single file
  15. File name - give the script a name with the extension .sql
  16. Save as Unicode text
  17. Click next
  18. Open out options using the plus sign
  19. Check the settings are all ok in the summary - you are mainly looking at the version and the types of data to script
  20. Click next
  21. Wait for it to run, you should see green ticks all the way down if it was successful.
  22. Click on Finish
  23. Then go to the location where you saved the script.
  24. Open the script
  25. Make sure the path of the files for the .mdf and log.ldf files is correct.
  26. Run the script
  27. You may get some errors like this: Cannot add the Principal 'CodeShare' because it does not exist or you do not have permission It is fine to ignore this. It's never caused me an issue.

Steps are taken from this article and helped me many times.

If your script is very large with data you can load it with CMD:

  1. Open a command prompt window.
  2. In the Command Prompt window, type: sqlcmd -S myServer\instanceName -i C:\myScript.sql
  3. Press ENTER.

Path in step 2 is only simple sample of course.

Another way is to script only database schema without data and recreate it on target server with lower version of SQL Server. Next you can connect to both instances with SSMS and copy data from one instance to another, but you have to remember about correct copying order if you have defined relations between tables. Removing relations and recreating them can be good strategy in this case (remember, that you got them in generated script). Another trap doing it this way are primary key/identity columns - default setting prevents inserting data into such columns, but you can achieve this running command:

SET IDENTITY_INSERT dbo.YourTableName ON;

After successful insert you should also run:

SET IDENTITY_INSERT dbo.YourTableName OFF;

Hope this manual will help you.

Upvotes: 1

user11272931
user11272931

Reputation: 1

A bit late here, but hope this will help others. I received a similar issue and updating both servers to the latest CU fixed it for me.

Upvotes: 0

Related Questions