473,839 Members | 1,421 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to find the SQL Server 2005 port

I am using a System.Data.Sql Client.SqlConne ction to connect to a SQL
Server 2005 database. I instantiate the SqlConnection with a
connection string...

SqlConnection sqlConn = new SqlConnection(@ "Network
Library=DBMSSOC N;Data Source=(local)" +
",1433;Database =CATHYDB;User
id=cathy;Passwo rd=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 26038
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**********@y ahoo.co.ukwrote in message
news:11******** *************@q 19g2000prn.goog legroups.com...
>I am using a System.Data.Sql Client.SqlConne ction to connect to a SQL
Server 2005 database. I instantiate the SqlConnection with a
connection string...

SqlConnection sqlConn = new SqlConnection(@ "Network
Library=DBMSSOC N;Data Source=(local)" +
",1433;Database =CATHYDB;User
id=cathy;Passwo rd=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**********@y ahoo.co.ukwrote in message
news:11******** *************@q 19g2000prn.goog legroups.com...
>I am using a System.Data.Sql Client.SqlConne ction to connect to a SQL
Server 2005 database. I instantiate the SqlConnection with a
connection string...

SqlConnection sqlConn = new SqlConnection(@ "Network
Library=DBMSSOC N;Data Source=(local)" +
",1433;Database =CATHYDB;User
id=cathy;Passwo rd=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.c omwrote:

<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.co mwrote in message
news:11******** **************@ z28g2000prd.goo glegroups.com.. .
On Jun 12, 12:49 pm, "Mr. Arnold" <MR. Arn...@Arnold.c omwrote:

<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.c omwrote:
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.co mha scritto nel messaggio
news:11******** **************@ z28g2000prd.goo glegroups.com.. .
On Jun 12, 12:49 pm, "Mr. Arnold" <MR. Arn...@Arnold.c omwrote:

<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.co mwrote in message
news:11******** **************@ i13g2000prf.goo glegroups.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.co mwrote in message
news:11******** **************@ i13g2000prf.goo glegroups.com.. .
On Jun 12, 1:38 pm, "Mr. Arnold" <MR. Arn...@Arnold.c omwrote:
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
9244
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 16, state1 SQL server does not exist or denied access.
4
2200
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 (written in Delphi) , the other is a web page (ASP). >From what I can tell, both different methods use the same port (1433) to access the data and create an open connection. We can telnet to this before a problem and suspect that we can't afterwards....
9
2706
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 2000. In my case the server I couldn't reach was across a vpn connection, behind ISA server 2000, (which had port 1433 open). The answer was in this post:...
10
13697
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 is on SQL Server 2000(on which everything works fine). Part of the testing process we tried to connect our website on SQL 2005 and it does not work at all.
5
20208
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 Explorer, then selecting Add - Existing Web Site...), then Visual Studio will create an ASP.NET Development Server on a random port (e.g., http://localhost:1619/Test). Can a similar thing be done during runtime with VB.NET? If not, is it possible to...
3
1500
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 path doesn't map to the url. Is there some trick to using different port numbers? Thanks. Jerry
0
1735
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 protocol to the non-standard port in both the server and client network configuration. I can add the SQL2000 server to the Management Studio console without problems, and even without haveing to specify the port I'm using (as expected)
8
7285
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 even though I have opened port 1433 in isa 2004 we can't access the remote sql server anymore. Where can I look for any blocks? Many Thanks
0
3843
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 2433 and -I dont know why- I cannot switch it to port 1433. When trying to push a new subscription on SERVER1 to SERVER2, it tells that:
0
9698
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10910
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10654
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9426
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7833
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7021
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5683
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
4066
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3136
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.