Unable to open default database after delete and restore it with a backup from another computer


I’m using SQL Server 13.0.4259.

I have created an user for my database with this script:

— Create TRZF db user.

USE [master] GO  if not exists(SELECT name                  FROM [master].[sys].[server_principals]                WHERE name = N'trzf_user') begin     CREATE LOGIN [trzf_user] WITH PASSWORD = '**********', DEFAULT_DATABASE=[$  (DatabaseName)], DEFAULT_LANGUAGE=[Español] end  USE [$  (DatabaseName)] GO  IF NOT EXISTS (SELECT name                  FROM [sys].[database_principals]                 WHERE name = N'trzf_user') Begin     CREATE USER [trzf_user] FOR LOGIN [trzf_user] WITH DEFAULT_SCHEMA=[dbo] end ALTER ROLE [db_datareader] ADD MEMBER [trzf_user] ALTER ROLE [db_datawriter] ADD MEMBER [trzf_user]  GRANT EXECUTE TO [trzf_user]  GO 

But I have had to delete it and restore it from another client’s database. After doing that, I have tried to login with the user trzf_user, using Management Studio, but I get this error message:

Unable to open user default database. Login error. Login failed for user 'trzf_user'. (.Net SqlClient Data Provider) 

I have tried this script:

USE [master] GO  ALTER LOGIN [trzf_user] WITH DEFAULT_DATABASE=[TRZIC-F] GO  USE [TRZIC-F] GO  IF NOT EXISTS (SELECT name                  FROM [sys].[database_principals]                 WHERE name = N'trzf_user') Begin     CREATE USER [trzf_user] FOR LOGIN [trzf_user] WITH DEFAULT_SCHEMA=[dbo] end ALTER ROLE [db_datareader] ADD MEMBER [trzf_user] ALTER ROLE [db_datawriter] ADD MEMBER [trzf_user]  GRANT EXECUTE TO [trzf_user]  GO 

But I’m can’t login.

How can I fix this problem?

I have run all the scripts and restored the database using sa user.

Before deleting the database, I can login with user trzf_user.