If you have installed 2 SQL Server instances on one machine, then is at least one a "named instance" and you have to additional add the instance name to server name in your connection string,
e.g.
Server=MachineName\InstanceName;Database=...
SQL server network setting port numbers are empty
That means, the instance uses dynamically ports and the port can change on every restart. You can assign a fix port, see
https://learn.microsoft.com/en-us/sql/database-engine/configure-windows/configure-a-server-to-listen-on-a-specific-tcp-port?view=sql-server-ver15