SQL Server – How to Import Binary Dump File

sql serversqlcmd

I am trying to import a dump file which is in binary format to SQL Server using sqlcmd command. After running the import command, I am getting this error, Msg 2812, Level 16, State 62 I'm suspecting that it is because the file is in binary format. Is there a way to directly import binary dump file to SQL Server? I tried using the -u flag but I'm getting the same error.

Sorry, forgot to mention, I am using SQL Server 2017 on Ubuntu 16.04

Command: sqlcmd -S localhost -d TestDB -U SA -u -i /home/user1/Downloads/myspecialpresentforyou

Error Message: Msg 2812, Level 16, State 62, Server user1, Line 1
Could not find stored procedure 'TAPE'.

Best Answer

The problem of tango ward is that he tries to pass full backup filee as a script file to sqlcmd. I understood it as he wrote the error is

Could not find stored procedure 'TAPE'.

The first bytes of a backup file even if it's disk file are 'TAPE':

enter image description here

To make a simplest restore from the bak file without restoring it to another database and moving the files you still can use sqlcmd, but you should pass your file as a backup file location, i.e. use this command:

restore database MyDB from disk = '/home/user1/Downloads/myspecialpresentforyou'

Here is simple example of doing it in sqlcmd:

  • First I launch sqlcmd (without parameters I'll connect to my default instance with win authentication, but you should use your sa user and password as you did)
  • Once launched sqlcmd you'll see 1> it's a prompt to enter your command, now enter there RESTORE...(the whole command, see above) and after entering it (press ENTER) you'll see 2>
  • Now enter GO to send your command

Here is how I restored my database abc from full backup Z:\Anna\backups\default\abc_full.bak

enter image description here

If you restore to another database you should first know logical file names using restore filelistonly and then move the files to new destination.

If it's your case you'd better use SSMS to see these files as sqlcmd output can be combersome if your db has many files.

Here the example in SSMS:

enter image description here