It really is not a matter a "Programming", it is a matter of "Configuration".
If the server is visible to the internet; it is simply a matter of having the servers URL or IP address and then setting your connection string to it. This is the method that is used by many web hosting companies. Your connection strings would look something like this
="1.0"="utf-8"
<configuration>
<connectionStrings>
<add name="DB-1" connectionString="Data Source=MSSQL.MyDomain.com; Initial Catalog=DB1; User ID=DB1_User; Password=DB1_Password; " />
<add name="DB-2" connectionString="Data Source=127.0.0.1:1433; Initial Catalog=DB2; User ID=DB2_User; Password=DB2_Password; " />
</connectionStrings>
</configuration
If your server is not visible to the internet, you have two options; either you configure the instance of SQL Server to be visible on the internet or you would need to set up a VPN. Neither of these are a simple answer suitable for this forum, but there is plenty of documentation depending on which way you choose to go.
Configure SQL Server for remote connections is pretty straight forward:
https://docs.sdl.com/LiveContent/content/en-US/SDL%20Tridion%20Docs-v1.1.2/GUID-CF5C89EA-0918-4002-8391-80CBEDE0BB5E[
^]
Configuring a VPN is going to depend on which VPN service you go with
The Verge : How to set up a VPN[
^]