Hello BonnieDeWitt-QnA
i am using C# windows form application
regards
NazHim
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi All,
how to connect Remote SQL Server Database. through the internet using Public Static IP and Port Number..?
in remote machine. i am used SQL Server 2019.
i want to connect remote SQL Server Database. with using public static IP 126.158.2.125 and Port 50121.
from Local Machine.
i am created port with number 50121.
created firewall Rules also. like image at below.
in Windows defender firewall
TCP Inbound Rules.
UDP Outbound Rules.
Connection Local:
it's working fine.
used Connection string like at below.
Server Local Machine IP: 192.168.1.17 (sample)
Port Number: 50121.
SqlConnectionStringBuilder sqlConBui = new SqlConnectionStringBuilder();
sqlConBui.DataSource = @"192.168.1.17,50121\STUDENTMSSQLSERVER";
sqlConBui.InitialCatalog = "StudentDatBas";
sqlConBui.PersistSecurityInfo = true;
sqlConBui.MultipleActiveResultSets = true;
sqlConBui.UserID = "Student";
sqlConBui.Password = "Stu1234";
string connectionString = sqlConBui.ConnectionString;
try
{
SqlConnection con = new SqlConnection(connectionString);
con.Open(); // Open the connection
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
i want to Access SQL Server DataBase from Remote machine. through the internet.
with using public static IP Address and specific port number.
Remote Connection:
it's not working.
used Connection string like at below.
Public Static IP: 126.158.2.125 (sample)
Port Number: 50121.
SqlConnectionStringBuilder sqlConBui = new SqlConnectionStringBuilder();
sqlConBui.DataSource = @"126.158.2.125,50121\STUDENTMSSQLSERVER";
sqlConBui.InitialCatalog = "StudentDatBas";
sqlConBui.PersistSecurityInfo = true;
sqlConBui.MultipleActiveResultSets = true;
sqlConBui.UserID = "Student";
sqlConBui.Password = "Stu1234";
string connectionString = sqlConBui.ConnectionString;
try
{
SqlConnection con = new SqlConnection(connectionString);
con.Open(); // Open the connection
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
getting error.
like image at below.
Port Result:
SQL Server Image:
SQL Server Configuration Manager:
how i can do it..?.
can provie some code snippet..?.
with best Regards.
NazHim
Hello BonnieDeWitt-QnA
i am using C# windows form application
regards
NazHim
Here is a sample connection string, @NazHim :
"server=TheIPAddress;uid=TheUser;pwd=ThePassword;database=TheDatabase"
Replace your values in the string.
you opened the firewall on the sqlserver windows box, but did you enable port forwarding from its modem?
hello Cris Zhan-MSFT
thanks for your fast response.
i am tried. 126.158.2.125,50121 (IP is sample not real)
bad luck. not working it.
regards
NazHim
Hi,
> sqlConBui.DataSource = @"126.158.2.125,50121\STUDENTMSSQLSERVER";
Please try "126.158.2.125,50121"
>network-related or instance-specific error occurred while establishing...
This error usually means that the client can't find the SQL Server instance.
If you cannot connect SQL Server through your application, please confirm whether the network and port is work fine, and try to use SSMS to remotely connect to the SQL Server instance for testing to explore where the problem may be.
https://learn.microsoft.com/en-us/sql/database-engine/configure-windows/troubleshoot-connecting-to-the-sql-server-database-engine?view=sql-server-ver15