If the Management Studio is not available, we can perform these same steps using the SQLCMD from the
Command Prompt. We will need to use the -S parameter to log into the SQL instance. You would use this
command to log into both the source and target instance.
Sqlcmd -S <servername\InstanceName> eg: sqlcmd -S .\VeeamSQL2012
Next connect to the master database
We can then use the following command to detach the database
eg: sp_detach_db ‘VeeamBackup’
To attach the database to the new instance after following the previously listed steps to connect to the new server/instance use the following command.
sp_attach_db 'database name','location of mdf','location of logs'
eg: sp_attach_db 'VeeamBackup','C:\Program Files\Microsoft SQL Server\MSSQL11.VEEAMSQL2012\MSSQL\DATA\Veeambackup.mdf','C:\Program Files\Microsoft SQL Server\MSSQL11.VEEAMSQL2012\MSSQL\DATA\VeeamBackup_log.ldf'
Then we can perform this command to login to the remote server:
SQLCMD -S 192.168.85.3\SQLEXPRESS
Followed by this command to perform the attach operation:
EXEC sp_attach_db @dbname = N'VeeamBackup',
@filename1 = N'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\VeeamBackup.mdf',
@filename2 = N'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\VeeamBackup_log.ldf';
Now, you can perform this task programmatically or without the help of Microsoft SQL Management Studio.