473,329 Members | 1,536 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,329 software developers and data experts.

How to find the SQL Server 2005 port

I am using a System.Data.SqlClient.SqlConnection to connect to a SQL
Server 2005 database. I instantiate the SqlConnection with a
connection string...

SqlConnection sqlConn = new SqlConnection(@"Network
Library=DBMSSOCN;Data Source=(local)" +
",1433;Database=CATHYDB;User
id=cathy;Password=pswd;");

When this code runs I can guarantee that everything about it will be
constant, except the port (here I've coded it as 1433).

I want to avoid hard-coding the port number. So, how can I either

a) find out which port SQL Server 2005 is using, or
b) use a different approach which doesn't require a hard-coded port
number?

Many thanks,

Cathy

Jun 12 '07 #1
9 26006
Hi Cathy,

There are 65,536 TCP ports on any machine. So, you can't exactly "discover"
the port, and that's not generally done. It is always expected that the
client will know what port to look at.

If you don't want to hard code the port number into your Connection String,
host the SQL Server on its' default port.

--
HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net

"Cathy" <ca**********@yahoo.co.ukwrote in message
news:11*********************@q19g2000prn.googlegro ups.com...
>I am using a System.Data.SqlClient.SqlConnection to connect to a SQL
Server 2005 database. I instantiate the SqlConnection with a
connection string...

SqlConnection sqlConn = new SqlConnection(@"Network
Library=DBMSSOCN;Data Source=(local)" +
",1433;Database=CATHYDB;User
id=cathy;Password=pswd;");

When this code runs I can guarantee that everything about it will be
constant, except the port (here I've coded it as 1433).

I want to avoid hard-coding the port number. So, how can I either

a) find out which port SQL Server 2005 is using, or
b) use a different approach which doesn't require a hard-coded port
number?

Many thanks,

Cathy

Jun 12 '07 #2

"Cathy" <ca**********@yahoo.co.ukwrote in message
news:11*********************@q19g2000prn.googlegro ups.com...
>I am using a System.Data.SqlClient.SqlConnection to connect to a SQL
Server 2005 database. I instantiate the SqlConnection with a
connection string...

SqlConnection sqlConn = new SqlConnection(@"Network
Library=DBMSSOCN;Data Source=(local)" +
",1433;Database=CATHYDB;User
id=cathy;Password=pswd;");

When this code runs I can guarantee that everything about it will be
constant, except the port (here I've coded it as 1433).

I want to avoid hard-coding the port number. So, how can I either

a) find out which port SQL Server 2005 is using, or
b) use a different approach which doesn't require a hard-coded port
number?

SQL Server no matter what version it is from 6.0 to 2005 uses ports 1433 and
1434. Those are the standards. SQL Server is not going to be listening on
any other ports.

And why are you hard coding the port number? The only database solution I
have seen where the port number had to be give was Oracel using NHibernate.


Jun 12 '07 #3
Sorry to be the bearer, but you can specify any port you like (within
reason) via the network configuration tool / server network utility.
1433 is just the default (although a very common default [i.e.
probably 99%+])

Marc
Jun 12 '07 #4
On Jun 12, 12:49 pm, "Mr. Arnold" <MR. Arn...@Arnold.comwrote:

<snip>
SQL Server no matter what version it is from 6.0 to 2005 uses ports 1433 and
1434. Those are the standards. SQL Server is not going to be listening on
any other ports.
Well, those are the defaults - for the default instance. It can be
changed even for the default instance, and I *think* each instance
will have its own port, so if you've got more than one instance then
at least *one* of them will be listening on a port other than the ones
you listed.

Jon

Jun 12 '07 #5

"Jon Skeet [C# MVP]" <sk***@pobox.comwrote in message
news:11**********************@z28g2000prd.googlegr oups.com...
On Jun 12, 12:49 pm, "Mr. Arnold" <MR. Arn...@Arnold.comwrote:

<snip>
>SQL Server no matter what version it is from 6.0 to 2005 uses ports 1433
and
1434. Those are the standards. SQL Server is not going to be listening on
any other ports.

Well, those are the defaults - for the default instance. It can be
changed even for the default instance, and I *think* each instance
will have its own port, so if you've got more than one instance then
at least *one* of them will be listening on a port other than the ones
you listed.
But I guarantee that 99.9% of SQL Servers are not listing on any other ports
and are using the standard ports. If different ports were being used, even
if I was pointing to another instance, that would be a know factor, and I
wouldn't be trying to come up with something to find SQL Server on high
ports. :)
Jun 12 '07 #6
On Jun 12, 1:38 pm, "Mr. Arnold" <MR. Arn...@Arnold.comwrote:
Well, those are the defaults - for the default instance. It can be
changed even for the default instance, and I *think* each instance
will have its own port, so if you've got more than one instance then
at least *one* of them will be listening on a port other than the ones
you listed.

But I guarantee that 99.9% of SQL Servers are not listing on any other ports
and are using the standard ports.
Agreed. That's not the same as saying that SQL Server is not going to
be listening on any other ports though.

Jon

Jun 12 '07 #7
True.
Every instance uses a different TCP port. Named instances use, by default,
dynamic ports, and will change on every restart.
A named instance can be bound to a specific port but that's not necessary
with SQL 2005, because of SQL Browser service.
SQL Browser implements a lookup service via UDP 1434 (that will not change
easily) that the client uses to find out the port the named instance is
using.

http://msdn2.microsoft.com/en-us/lib...7(SQL.90).aspx
"Jon Skeet [C# MVP]" <sk***@pobox.comha scritto nel messaggio
news:11**********************@z28g2000prd.googlegr oups.com...
On Jun 12, 12:49 pm, "Mr. Arnold" <MR. Arn...@Arnold.comwrote:

<snip>
>SQL Server no matter what version it is from 6.0 to 2005 uses ports 1433
and
1434. Those are the standards. SQL Server is not going to be listening on
any other ports.

Well, those are the defaults - for the default instance. It can be
changed even for the default instance, and I *think* each instance
will have its own port, so if you've got more than one instance then
at least *one* of them will be listening on a port other than the ones
you listed.

Jon
Jun 12 '07 #8
"Jon Skeet [C# MVP]" <sk***@pobox.comwrote in message
news:11**********************@i13g2000prf.googlegr oups.com...
Agreed. That's not the same as saying that SQL Server is not going to
be listening on any other ports though.
Quite so - one of my current clients has all of its SQL Server instances
running on ports above 50,000...

It's the usual story - somebody somewhere read something which said that
running SQL Server on the default port (even on internal networks) was a
massive security risk, so they went into panic mode and changed them all...
:-)
--
http://www.markrae.net

Jun 12 '07 #9

"Jon Skeet [C# MVP]" <sk***@pobox.comwrote in message
news:11**********************@i13g2000prf.googlegr oups.com...
On Jun 12, 1:38 pm, "Mr. Arnold" <MR. Arn...@Arnold.comwrote:
Well, those are the defaults - for the default instance. It can be
changed even for the default instance, and I *think* each instance
will have its own port, so if you've got more than one instance then
at least *one* of them will be listening on a port other than the ones
you listed.

But I guarantee that 99.9% of SQL Servers are not listing on any other
ports
and are using the standard ports.

Agreed. That's not the same as saying that SQL Server is not going to
be listening on any other ports though.
You can change a Web server not ot listen on TCP 80 as well. But since I am
not a DBA and would have no reason to know that SQL can run on other ports,
because that's all I have seen is the standards for connecting to SQL Server
in the many shops I have worked in, then so be it, as I have actually
learned something new about SQL Server.

And I'll also say that a vast majority of so called SQL Server Admins don't
know it either. They would just put up another SQL Server box.

Jun 12 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Danieltbt05 | last post by:
just installed SQL server 2000 and using my client , i can't locate the server. I used SQL query analyzer to search but no servers were found. Error message is as below Server : Msg17,level...
4
by: Ryan | last post by:
We have two applications (1 on two servers and 1 on another). Every so often, we 'lose' the connection to the SQL database which in effect takes these applications down. One app is a service...
9
by: RvGrah | last post by:
After much hair-pulling, I've finally found the answer to a problem that many are fighting with, difficulty connecting from Sql 2005 Server Management or VS2005 to a remote Sql Server running Sql...
10
by: MVChauhan | last post by:
Hi We are planning to move over to SQL Server 2005 in near future. At the moment Website is on a seperate server then the Database. OS for both the server is Window 2003 and currently our data...
5
by: ljlevend2 | last post by:
Is there any way to create a local server during runtime? For example, if you add an existing Web Site to a Solution from within Visual Studio (by right clicking the solution in the Solution...
3
by: | last post by:
I'm trying to create a project on a virtual server that runs on port 8000, rather than port 80. I tried creating the project at http://localhost:8000/MyFolder but it keeps telling me that the file...
0
by: basuritta | last post by:
I am trying to add a SQL2000 subscriptor to a SQL2005 publisher and distributor using the Management Studio. I'm using a non-standard port in both ends, but I have set the port for the TCP/IP...
8
by: John | last post by:
Hi We had an sbs 2003 with isa 2000 server. We wre able to access a remote sql server (hosted at our web host) just fine. We replaced the server with a new sbs 2003 r2 with isa 2004 server and...
0
by: shgzs33 | last post by:
I have 2 SQL 2005 Servers SERVER1 and SERVER2 and want to establish a replication betwwen them: SERVER1 as Publisher and SERVER2 as subscriber. the problem is that SERVER2 is runnint on port...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.