After GP Company database restore: The selected company is not configured as a company of the current Microsoft Dynamics GP syst

After restoring a GP Company Database from another SQL server you may get the following error when trying to log into the restored company:

“The selected company is not configured as a company of the current Microsoft Dynamics GP system database. You must resolve the database configuration to log in to the company”

The following SQL scripts may resolve the issue.

select
CompanyDbId = c.CMPANYID
,DynamicsDbId = d.CMPANYID
,DynamicsDbName = d.INTERID
,DynamicsCompanyName = d.CMPNYNAM
from sy00100 c
left join dynamics..sy01500 d
on d.interid = db_name()

–update SY00100 set CMPANYID = (select CMPANYID from DYNAMICS..sy01500 where INTERID = db_name())