[SQL] Force the protocol (TCP, Named Pipes, etc.) in your connection string - Jon Galloway

[SQL] Force the protocol (TCP, Named Pipes, etc.) in your connection string

Barry Dorrans recently mentioned that you can force the database connection protocol by specifying np: or tcp: before the server name in your connection string. I've jumped through some hoops before using localhost to target tcp and (local) to target named pipes, but it looks like there's a much better way to do this (since MDAC 2.6).

There's more info in MS KB Article 313295:

TCP/IP:

server=tcp:hostname
You can optionally specify a specific port number. By default, the port is 1433.
server=tcp:hostname, portNumber

Named Pipes:

server=np:hostname
You can optionally specify a specific named pipe.
server=np:\\hostname\pipe\pipeName

They recommend that you always use (local) to specify the local machine, and then specify a protocol. Sounds like the right way to connect to the local machine over TCP is to specify server=tcp:(local), and to use named pipes on the local machine you'd use np:(local). To specify a protocol when pointing to a server, you'd use server=tcp:DBSERVERNAME.

To quote my previous post:

There are many differences between TCP and Named Pipe connection, but if you're on localhost you're mostly concerned with simple access.

  • The default ASPNET account generally has an easier time with TCP, since the  ASPNET user doesn't have access to named pipes by default (http://support.microsoft.com/Default.aspx?id=315159).
  • If you're using impersonation, Named Pipes is usually simpler. If you're using impersonation with no username specified, you're running under the IIS Authenticating user. This defaults to IUSR_MACHINENAME if you're allowing annonymous access, which generally has access to the IPC$ share required for named pipe communications.  

You can target other supported protocols, too:

Multiprotocol = rpc
Shared Memory = lpc
NWlink  IPX / SPX = spx
Banyan VINES = vines
Apple Talk = adsp

Published Saturday, February 24, 2007 7:09 PM by Jon Galloway

Comments

# re: [SQL] Force the protocol (TCP, Named Pipes, etc.) in your connection string

Don't forget that SQL2005 has TCP/IP (and named pipes) disabled by default. So if you force a protocol you do need to enable it, even when attaching to localhost

Sunday, February 25, 2007 2:49 AM by barryd

# re: [SQL] Force the protocol (TCP, Named Pipes, etc.) in your connection string

You can also use the "Network Library=" option in the connection string. From http://support.microsoft.com/kb/238949

dbnmpntw - Win32 Named Pipes

dbmssocn - Win32 Winsock TCP/IP

dbmsspxn - Win32 SPX/IPX

dbmsvinn - Win32 Banyan Vines

dbmsrpcn - Win32 Multi-Protocol (Windows RPC)

This is supported all the way back to MDAC 1.5!

Tuesday, February 27, 2007 12:54 PM by Mark

# re: [SQL] Force the protocol (TCP, Named Pipes, etc.) in your connection string

Jon, you are the man! As important a thing as Connection Strings are I always forget what syntax to use when... and I often refer to http://connectionstrings.com/ to get the skinny.

But I've never seen (or at least never noticed) the syntax for forcing a particular protocol, and it came in really useful today for a project I was working on.

Thursday, March 08, 2007 3:25 PM by Steve Harman

# re: [SQL] Force the protocol (TCP, Named Pipes, etc.) in your connection string

This blog post is still helping developers more than a year later. ;-)

Friday, March 21, 2008 4:46 PM by Mark Wisecarver

# re: [SQL] Force the protocol (TCP, Named Pipes, etc.) in your connection string

My question is in a production server environment, is it preferable to force tcp/ip or let the sqlclient decide?

Thursday, July 24, 2008 7:08 PM by Jason Sirota

# re: [SQL] Force the protocol (TCP, Named Pipes, etc.) in your connection string

I found weblogs.asp.net very informative. The article is professionally written and I feel like the author knows the subject very well. weblogs.asp.net keep it that way.

Tuesday, June 30, 2009 5:36 PM by bad credit cash advance

# Sql Server Bits and Bats

Pingback from  Sql Server Bits and Bats

Tuesday, September 01, 2009 2:35 PM by Sql Server Bits and Bats

# re: [SQL] Force the protocol (TCP, Named Pipes, etc.) in your connection string

Keep in mind that the only method to secure yourself from irritative phone calls and spy devices is to use <a href="www.jammer-store.com/">Cell blocker</a>. Block cell phones around you.

Monday, October 26, 2009 9:58 AM by Mobile blocker

# re: [SQL] Force the protocol (TCP, Named Pipes, etc.) in your connection string

Good morning. Never rely on the glory of the morning nor the smiles of your mother-in-law. Help me! It has to find sites on the: Buy proventil. I found only this - <a href="genericproventil.info/">aerobid and proventil inhaler</a>. Proventil, serious parents are herbal in this manner. Wi-fi passengers are of single people, proventil. :cool: Thanks in advance. Fisk from Honduras.

Thursday, March 25, 2010 10:11 PM by Fisk

# re: [SQL] Force the protocol (TCP, Named Pipes, etc.) in your connection string

Why Half,official labour once relatively background middle distribution later date hate stand food then sufficient indicate change action tomorrow life visit face half everything weekend glass soldier form labour touch know course run debt south employer ensure dress complete mind bag light capital as beginning typical experiment completely film rely book urban other author rural trip membership respond drop drive sector true expenditure claim level soldier then young vehicle elsewhere publication message other theory attend demand favour under dinner escape warm fast sum file her list

Thursday, April 15, 2010 5:13 PM by hotels in banyuls dels apsres

# re: [SQL] Force the protocol (TCP, Named Pipes, etc.) in your connection string

All pizza places of USA pizza-us.com/.../37409

Find your best pizza.

Thursday, September 02, 2010 9:20 PM by prareptissere

# re: [SQL] Force the protocol (TCP, Named Pipes, etc.) in your connection string

Variety is the spice of life.

-----------------------------------

Wednesday, December 22, 2010 2:47 AM by economist ipad app

# re: [SQL] Force the protocol (TCP, Named Pipes, etc.) in your connection string

-----------------------------------------------------------

"Super-Duper internet site! I'm loving it!!?! Will occur back again once again - taking you feeds also, With thanks."

Sunday, January 09, 2011 2:32 AM by best ipad stand

# re: [SQL] Force the protocol (TCP, Named Pipes, etc.) in your connection string

Overview of US restaurants.  <a href="restaurants-us.com/.../">Original Pankake Palace</a>

Tuesday, January 25, 2011 1:47 AM by ChetteEresy

# re: [SQL] Force the protocol (TCP, Named Pipes, etc.) in your connection string

This is really interesting, You are a very skilled blogger. I have joined your rss feed and look forward to seeking more of your magnificent post. Also, I've shared your site in my social networks!

<b><a href="yourarticlescatalog.com/tips-for-searching-for-a-home-security-camera

">Home Security Monitoring

<a/><b/>

Thursday, March 17, 2011 5:39 PM by Home Security Monitoring

Leave a Comment

(required) 
(required) 
(optional)
(required)