Click here to Skip to main content
15,901,426 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi,
I obtained IP address of the target computer using:
C#
Dim hostname As String = Dns.GetHostName()
       Dim vrIPAddress As String = CType(Dns.GetHostByName(hostname).AddressList.GetValue(0), IPAddress).ToString


Then i tried to connect with that computer using connection string:
C#
"Data Source=192.168.0.2,1433\MyInstance;Network Library=DBMSSOCN;Initial Catalog=myDataBase;User ID=myUsername;Password=myPassword;


After a long pause, it says:
VB
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 0 - A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.)


The target system is configured for Firewall, allows Remote Connection etc, allows both TCP/IP connections.

Please advise.
Thanks

What I have tried:

I have searched google, tried different code snippets
Posted
Updated 28-Feb-16 7:22am
Comments
Richard MacCutchan 24-Feb-16 7:32am    
The address 192.168.0.2 is the address of your system, not the remote one. Why not just ask the administrator for its address?
Furqan Sehgal 24-Feb-16 7:36am    
There is no administrator, how can I check the address myself?
ZurdoDev 24-Feb-16 8:10am    
1. Reply to the comment so that the user is notified.
2. You don't need the 1433 on the connection string. Is the server on your network?
Furqan Sehgal 25-Feb-16 2:07am    
1) Thanks for the tip!
2) No, I want to access the remote server over internet
ZurdoDev 25-Feb-16 7:27am    
Then it needs to have that port open, which is not normal for external access. You probably should get with a tech guy and create a vpn or have them forward a port for you.

The port for sql connection is not open at the server level and you cant do much about the same unless you are getting the proper ip address with the port.
 
Share this answer
 
If you're trying to connect to MS SQL Server placed on another computer, take a look here:
Lesson 2: Connecting from Another Computer[^]
How to: Enable the TCP/IP Protocol for a Database Instance[^]
In some cases, you'll need to Configure the Windows Firewall to Allow SQL Server Access[^]

But, it seems you want to connect to MS SQL Server on local machine. Many useful information about "connection string" you'll find here: SQL Server connection strings - ConnectionStrings.com[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900