Connecting to Sql Server using an IP address

  • Thread starter Thread starter David Thielen
  • Start date Start date
D

David Thielen

Hi;

We can connect fine using ADO.NET when we connect to a server by name.
But when we try to connect by IP address, it works for systems on our
subnet, but not for machines further away - including ones that we can
connect to by name.

We pass the IP address as the name of the server. Do we need to use
something other than Data Source=1.2.3.4 and/or put something else in
the connection string?

thanks - dave


david@[email protected]
Windward Reports -- http://www.WindwardReports.com
me -- http://dave.thielen.com

Cubicle Wars - http://www.windwardreports.com/film.htm
 
PS - I forgot, if there is a different syntax:

1) How is this used for the native Sql Server ADO.NET connection, ODBC
ADO.NET connection, and OleDb ADO.NET connection?

2) Does this difference hold for other vendors? And if so, the same
syntax change?

thanks - dave


Hi;

We can connect fine using ADO.NET when we connect to a server by name.
But when we try to connect by IP address, it works for systems on our
subnet, but not for machines further away - including ones that we can
connect to by name.

We pass the IP address as the name of the server. Do we need to use
something other than Data Source=1.2.3.4 and/or put something else in
the connection string?

thanks - dave


david@[email protected]
Windward Reports -- http://www.WindwardReports.com
me -- http://dave.thielen.com

Cubicle Wars - http://www.windwardreports.com/film.htm


david@[email protected]
Windward Reports -- http://www.WindwardReports.com
me -- http://dave.thielen.com

Cubicle Wars - http://www.windwardreports.com/film.htm
 
On the Network Library= vs Network= - which is it for the
SqlConnection, OdbcConnection, & OleDbConnection?

Also if the user types in the server and we have to determine if it's
an IP address vs a name, any suggestions on the best way? Because a
server name can start with a number. Can server names have a . in
them?

thanks - dave




david@[email protected]
Windward Reports -- http://www.WindwardReports.com
me -- http://dave.thielen.com

Cubicle Wars - http://www.windwardreports.com/film.htm
 
Hello David,

Your situation reminded me about another similar case: Under network
protocol TCP/IP, using IP address without port number (default port number
of SQL Server is 1433) cannot connect to the SQL Server on a remote
machine, using server name does not work either; under network protocol
named pipes, both using IP address without port number and using server
name in the connection string can connect the remote machine successfully.


The root cause of that case is the port number of SQL Server when
connecting under the network protocol TCP/IP. If the port has been
changed to other port numbers, we need to modify the connection string when
using IP address to connect to the SQL Server and add set the network
protocol as TCP/IP. The connection string can be "Data
Source=*.*.*.*,1500(the new port number);Network
Library=DBMSSOCN(TCP/IP)…". For detail, please see
http://www.connectionstrings.com/sql-server-2005 and
http://www.connectionstrings.com/Articles/Show/define-sql-server-network-pro
tocol.

Therefore, I recommend you start from checking the TCP/IP port setting to
troubleshoot this issue. Please refer to this article to check the port
setting in the SQL Server:
http://msdn.microsoft.com/en-us/library/ms177440(SQL.90).aspx.

If the problem is not caused by TCP/IP port settings, you can also follow
this KB article to check whether the remote SQL Server has been set
correctly to accept remote connections,
http://support.microsoft.com/kb/914277.

For your second question on how the native SQL Server ADO.NET connection,
ODBC ADO.NET connection and OLEDB ADO.NET connection accept the IP address,
please see the following analysis:
//////////////////////////////////////////////////////////////

Native SQL Server ADO.NET Connection:
Could you please clarify what do you mean by native SQL Server ADO.NET
conection?

//////////////////////////////////////////////////////////////

ODBC ADO.NET Connection:
For SQL Server:
You can use such an ODBC connection string to connect the database:
"Driver={SQL Server}; Server=***.***.***.***(IP address),****(port number);
Database=DatabaseName; Uid=***; Pwd=***".

For IBM DB2:
Here are the keywords in the connection string:
Keyword "NTL=TCPIP" for TCP/IP connection
Keyword "NA" for IP address and "NP" for network port
For detail, please see
http://msdn.microsoft.com/en-us/library/ms944772.aspx.

To connect other database software via ODBC connection string, you need to
consult corresponding vendor company.

//////////////////////////////////////////////////////////////

OLEDB ADO.NET Connection:
For SQL Server:
You can use such an OLEDB connection string to connect the database:
"Provider=SQLOLEDB;Data Source=***.***.***.***(IP address),****(port
number);Initial Catalog=DatabaseName;User ID=***;Password=***".

For IBM DB2:
Here are the keywords in the connection string:
Keyword "Network Transport Library=TCPIP" for TCP/IP connection
Keyword "Network Address=***.***.***.***" for IP address
For detail, please see http://www.connectionstrings.com/ibm-db2.

To connect other database software via OLEDB connection string, you need to
consult corresponding vendor company.

//////////////////////////////////////////////////////////////

For the third question about other vendors' connection string, please
understand that is not supported in Microsoft Newsgroup Supporting service.
You may consult the corresponding vendor company for the answer.

If you have any other questions, please be free to let me know. Have a
nice day, David!


Regards,
Lingzhi Sun ([email protected], remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

MSDN Managed Newsgroup support offering is for non-urgent issues where an
initial response from the community or a Microsoft Support Engineer within
2 business day is acceptable. Please note that each follow up response may
take approximately 2 business days as the support professional working with
you may need further investigation to reach the most efficient resolution.
The offering is not appropriate for situations that require urgent,
real-time or phone-based interactions. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hello David,

In this post, I'd like to discuss with you the three new questions that you
asked. If there is any misunderstanding, please be free to correct me.

///////////////////////////////////////////////////////////////////////////

Question 1: Does this connection string, "Data
Source=190.190.200.100,1433;Network Library=DBMSSOCN;Initial
Catalog=myDataBase;User ID=myUsername;Password=myPassword;" only work in
SQL Server 2008?

No, it is also supported in SQL Server 2005. You can refer to
http://www.connectionstrings.com/sql-server-2005 for additional
information.

///////////////////////////////////////////////////////////////////////////

Question 2: Should it be the "Network Library" attribute or the "Network"
attribute to set network protocol in SqlConnection, OdbcConnection and
OleDbConnection?

It is the "Network Library" attribute that determines the network protocol
used in the database connection string.

Here are some examples for SqlConnection, OdbcConnection and
OleDbConnection respectively. All the examples below work for SQL Server
2005 and SQL Server 2008. For other database software, please consult the
corresponding vendor company.

SqlConnection:
You can use such a connection string to create SqlConnection: "Data
Source=190.190.200.100,1433;Network Library=DBMSSOCN;Initial
Catalog=myDataBase;User ID=myUsername;Password=myPassword;".

DBMSSOCN is for TCP/IP, and DBNMPNTW for Named Pipes. For additional
information, please see
http://www.connectionstrings.com/Articles/Show/define-sql-server-network-pro
tocol.

OdbcConnection:
You can use such a connection string to create OdbcConnection: "Driver={SQL
Server};Network Library=TCPIP;Server=190.190.200.100,1433;Database=
myDataBase;Uid= myUsername;Pwd= myPassword "

OleDbConnection:
You can use such a connection string to create OleDbConnection:
"Provider=SQLOLEDB;Data Source=190.190.200.100,1433;Network
Library=DBMSSOCN;Initial Catalog= myDataBase;User ID= myUsername;Password=
myPassword".

///////////////////////////////////////////////////////////////////////////

Question 3: How to determine if we enter an IP address or a server name in
the connection string?

I think it can be determined by regex for IP address. For detail, please
check http://www.regular-expressions.info/examples.html and
http://www.regular-expressions.info/regexbuddy/ipaccurate.html for IPv4 IP
address, and http://regexlib.com/REDetails.aspx?regexp_id=1115 for IPv6 IP
address.


If you have any other questions, please be free to let me know.


Regards,
Lingzhi Sun ([email protected], remove 'online.')
Microsoft Online Community Support

=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

This posting is provided "AS IS" with no warranties, and confers no rights.
=================================================
 
thank you very much.


Hello David,

In this post, I'd like to discuss with you the three new questions that you
asked. If there is any misunderstanding, please be free to correct me.

///////////////////////////////////////////////////////////////////////////

Question 1: Does this connection string, "Data
Source=190.190.200.100,1433;Network Library=DBMSSOCN;Initial
Catalog=myDataBase;User ID=myUsername;Password=myPassword;" only work in
SQL Server 2008?

No, it is also supported in SQL Server 2005. You can refer to
http://www.connectionstrings.com/sql-server-2005 for additional
information.

///////////////////////////////////////////////////////////////////////////

Question 2: Should it be the "Network Library" attribute or the "Network"
attribute to set network protocol in SqlConnection, OdbcConnection and
OleDbConnection?

It is the "Network Library" attribute that determines the network protocol
used in the database connection string.

Here are some examples for SqlConnection, OdbcConnection and
OleDbConnection respectively. All the examples below work for SQL Server
2005 and SQL Server 2008. For other database software, please consult the
corresponding vendor company.

SqlConnection:
You can use such a connection string to create SqlConnection: "Data
Source=190.190.200.100,1433;Network Library=DBMSSOCN;Initial
Catalog=myDataBase;User ID=myUsername;Password=myPassword;".

DBMSSOCN is for TCP/IP, and DBNMPNTW for Named Pipes. For additional
information, please see
http://www.connectionstrings.com/Articles/Show/define-sql-server-network-pro
tocol.

OdbcConnection:
You can use such a connection string to create OdbcConnection: "Driver={SQL
Server};Network Library=TCPIP;Server=190.190.200.100,1433;Database=
myDataBase;Uid= myUsername;Pwd= myPassword "

OleDbConnection:
You can use such a connection string to create OleDbConnection:
"Provider=SQLOLEDB;Data Source=190.190.200.100,1433;Network
Library=DBMSSOCN;Initial Catalog= myDataBase;User ID= myUsername;Password=
myPassword".

///////////////////////////////////////////////////////////////////////////

Question 3: How to determine if we enter an IP address or a server name in
the connection string?

I think it can be determined by regex for IP address. For detail, please
check http://www.regular-expressions.info/examples.html and
http://www.regular-expressions.info/regexbuddy/ipaccurate.html for IPv4 IP
address, and http://regexlib.com/REDetails.aspx?regexp_id=1115 for IPv6 IP
address.


If you have any other questions, please be free to let me know.


Regards,
Lingzhi Sun ([email protected], remove 'online.')
Microsoft Online Community Support

=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

This posting is provided "AS IS" with no warranties, and confers no rights.
=================================================


david@[email protected]
Windward Reports -- http://www.WindwardReports.com
me -- http://dave.thielen.com

Cubicle Wars - http://www.windwardreports.com/film.htm
 
Back
Top