title: Login failed after MSSQL database restore
body: <p>I have two instances of the same software written in C++/CLI on two different computers, each app connected to its own MSSQL server. I need to backup one of the databases and restore it on the other computer through the app. I backup the database with the following query:</p>
  <pre><code>BEGIN SET NOCOUNT ON;
  BACKUP DATABASE [DB_NAME]
  TO DISK = N'[FILEPATH]'
  WITH NAME = N'full-database-backup';
  END;
  </code></pre>
  <p>While the restore query is the following:</p>
  <pre><code>USE [master];
  ALTER DATABASE [DB_NAME] SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
  RESTORE DATABASE [DB_NAME] FROM DISK = N'[FILEPATH]'
  WITH REPLACE, RECOVERY;
  ALTER DATABASE [DB_NAME] SET MULTI_USER WITH ROLLBACK IMMEDIATE;
  </code></pre>
  <p>After the restore I need to read the database again to refresh the data in the app, but when I try to open a new connection to the restored database it fails with the following error:</p>
  <pre><code>Cannot open database [DB_NAME] requested by the login. The login failed.
  Login failed for user '[USER_NAME]'.
  </code></pre>
  <p>I tried to use <code>sp_change_users_login</code> without success. Any suggestions?</p>