.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

[.Net 4, Named Pipes, Single-instance app] Critique the code, please

Posted By:      Posted Date: October 02, 2010    Points: 0   Category :.NET Framework

The code below is a prototype of single-instance component. Of course there's a lot of work to get it done: separate into an component, add different names per user session, run server in background thread and so on and so on.

Currently, I'm interested in finding wrong options supplied, invalid usages, security holes or anything I missed. E.g. I'm almost sure there's a bug: the code allows for remote connections. I'll prove it on monday, as I've no access to local network for now.

using System;
using System.IO;
using System.IO.Pipes;
using System.Security.AccessControl;
using System.Security.Principal;

namespace ProcessSingleInstance
 class Program
  static void Main(string[] args)
   string[] data = new[] { "a", "aaaaa", "qweqeqweqeqweqwert" };


View Complete Post

More Related Resource Links

Best Practices for WPF Single Instance with named pipes?

Hi, I've developed a WPF server-hub-typed application, and a bunch of client-typed applications. The hub app is always a single instance (using mutex), and implements named pipes.   However, I'm having problem with the clients. The clients are applications that send data to the hub. They need to start the hub if it is not already running.   The problem with these clients is, they are optional and portable. Hence, the user might store them in different locations on their system. I really do not wish to deploy the Hub application with every client. What's the best way for me to implement this?   Another thing, do I *have* to use Process.Start(path, args) to start my hub application?    I've attached a sample project that I've done. But there are several problems with it, which I've not figured out how to fix. http://www.sendspace.com/file/ykhdg0   Thanks Min Chew   [References I've used:] http://blogs.microsoft.co.il/blogs/maxim/archive/2010/02/13/single-instance-application-manager.aspx <-- This is the one that seems the most promising (single instance + IPC), but I want a bare-minimum example so I can get a better hang on things. Besides, it crashes when I click on any of the 3 Run buttons http://www.switchonthecode.com/tutorials/wcf-tutorial-basic-interprocess-communication <-- Named pipe IPC using wcf http://www.switchonthec

Named Pipes code

We created a very simplistic wrapper for named pipes. If all you need is a basic messag epipe, this should work for you. Code & info at Named Pipes in .NET thanks - daveVery funny video - Reporting as a Metaphor



.NET 3.5 Adds Named Pipes Support

you want a named pipe server, all you have to do is create some instances of NamedPipeServerStream to handle each client connection. I stole the following code straight from the MSDN documentation.

Inside Microsoft patterns & practices: Building WPF and Silverlight Applications with a Single Code


This article discusses the Project Linker tool and other techniques to create applications that target both WPF and Silverlight from a single code base.

Erwin van der Valk

MSDN Magazine August 2009

Issue with contacting named instance

Hi. I'm having problem with connecting to the named instance of SQL Server. The machine runs Windows 2008 x64 and SQL Server 2008 Std SP1+CU7. It holds 3 instances of service: default, and 2 named ones. We have 2 networks in our company. All instances can be contacted from the 1st localization (the one, which is local to the SQL), but the named instance cannot be contacted form the remote localization. What's amazing, users can connect to the default instance, but when they try to reach the named one, they receive message: 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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified) "Remote" users have permissions to the named instance - I've given them sysadmins to test, they can ping the SQL box and all works fine from the "local" network. Client is Win7+SSMS 2008. Please help.

Named Pipes provider error - backup script

I have a couple of installs of SQL Server 2005 Express.  One thing it doesn't provide is an agent to schedule jobs so I read where you can use Windows job scheduler to execute a batch job to in turn run a sqlcmd file.  I have that working on one server but on the other server I get the dreaded Name Pipes provider error and it goes on to talk about it may not be setup to allow remote connections.  If I check using Surface Configurator it is set to allow remote connections using both tcpip and named pipes.  To my knowledge all I want it tcpip but I enabled named pipes in an effort to get things working. About the only difference I can see is on the working system the database is a named instance (ie. Servername) versus default instance on the non-working system which shows up as (Servername\SQLEXPRESS).  Hopefully I have my terminology right here. Any tips on how to troubleshoot?  Does it depend on the username I am using?  Domain admin or local server admin or what have you? I should mention I can execute the backup script and it does work.  It is when I run the batch job that it fails. The batch job just says "sqlcmd -i d:\MSSQL_Jobs\backup.sql -o d:\Logs\sqlbackup_output.txt"

SQL 2008 R2 clustered instance does not start in single user mode

Hi I am testing the startup of a SQL 2008 R2 clustered instance (Windows 2008 R2) using single user mode but it fails with : Error: 17058, Severity: 16, State: 1. initerrlog: Could not open error log file ''. Operating system error = 3(The system cannot find the path specified.) - I am running the following command from the default sql installation : C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQL01\MSSQL\Binn>sqlservr.exe -c -m -s SQL01 - The cluster service on the passive node has been shutdown. - The SQL Server and SQL Agent services have been set to offline in Failover Cluster Manager. Any assistance greatly appreciated. Regards, PK    

named instance sql server 2008 install on cluster

I have a production two-node cluster with sql server 2008 sp1 cu7 running over windows server 2008 sp2. If I were to install a new named instance on this live environment, would it impair the default sql server instance functionality? I'm not referring to processor/io while the install is in progress. My question specifically is would the install process by its nature bring down the default instance. I'm pretty sure it won't, but don't see any documentation that would confirm this. thanks.

how to choose between Shared Memory, Named Pipes, TCP/IP, VIA?

What protocol to choose? Or, Why are they so many? I am mostly interested in contexts: 1)  development on local machine 2) development from remote machine (having SQL Server on another machine)  3) Production 4) what else should I bother/know about? I am developer, mostly using Developer Ed. mostly locally on Windows XP Pro SP3, and really had never bothered which protocol was used as far as connection was being successful. And I had never had any troubles to bother looking and choosing between protocols Why and when should I bother to choose between protocols for development?

How to use single windows service to host multiple WCF Services instances (Each instance of WCF is i

How to use single windows service to host multiple WCF Services. I have a mutiple instance of same WCF service in different folder, each instance has unique service name and port. WCFService has reference to Reg-Free COM Reference, i have Native.WCFService.manifest in each folder. Ex: WCFService1 is in "C:\WCFService01\WCFService.dll, Native.OCWCFService.manifest, OCWCFService.dll.config WCFService2 is in "C:\WCFService02\WCFService.dll, Native.OCWCFService.manifest, OCWCFService.dll.config Now i need host above services from single Windows Service. I am trying to create AppDomain for each above WCFService Instance from Windows Service and then host. Its working if i register COM dll in the server using regsvr32, but when i un register COM dll, i am getting unable to load COM component .... This looks like AppDomain is not loading COM DLL and Manifest files. Its looks strange but we need it in this way because we have production and test environment in the same server. Everything works fine if create a seperate Windows Service for each WCFService Instance, but my manager wants single Windows Service :). Any help whould be really appreciated.  ravi kumar reddy

Create Single SharePoint Instance

Hi All, I have created SharePoint 2007 (MOSS 2007) application using SQL Server 2008. The user requirement is, to have SINGLE INSTANCE so that any one user is allowed to have only one active session at a time. How to achieve this? Regards Sanra

OWC11 Nightmare!!! Can't Install Named Instance

I'm being driven demented by OWC11! Please help before they take me away! I'm trying to install a new named instance of SQL 2005 Enterprise 64 bit on a box which already has a default instance patched to SP3.

Setup barfs at the OWC11 stage and it complains about missing files I can't even find in the installation media. I have absolutely no idea what to do now. I tried uninstalling / reinstalling OWC11 but to no avail.

My boss thinks installing a new instance is simple and he'll think I'm an idiot if I can't resolve this. He may be right of course but I'm stuck.

Is this a bug? Sure smells like one. Will this go away at SQL 2008?

Sorry to dump a lot of text but here's the OWC setup log -

=== Verbose logging started: 22/09/2010 19:32:47 Build type: SHIP UNICODE 3.01.4000.4042 Calling process: C:\Program Files\Microsoft SQL Server\90\Setup Bootstrap\setup.exe ===
MSI (c) (0C:B4) [19:32:47:199]: Resetting cached policy values
MSI (c) (0C:B4) [19:32:47:199]: Machine policy value 'Debug' is 0
MSI (c) (0C:B4) [19:32:47:199]: ******* RunEngine:
******* Product: ******* Action:
******* CommandLine: **********
MSI (c) (0C:B4) [19:32:47:215]: Client-side and UI is none or basic: Running entire install on the serv

Named Pipes Provider, error: 40 - Could not open a connection to SQL Server


This was originally posted in the SSIS Forum, but a member of the IS team suggested it be moved here.  "Most recently I got this error (Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) so does this mean that SQL Server is still trying to use named pipes even if I only have TCP/IP enabled in SQL Server Configuration Manager?"

I'm having the same issue, and here's our scenario:

  1. Installed SQL Server 2005 Developer Edition on a machine with WinXP SP2 and enabled remote connections over TCP/IP
  2. Installed SQL Server 2005 Standard Edition on a machine with Win2003 SP1 (remote connections over TCP/IP enabled by default)
  3. Attempted to 'Copy Database' from Developer Edition TO Standard Edition using 'Detach and Attach' method and recieved the error on the Win2003 machine: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server
  4. A

How to use Named Pipes for Inter Process Communication and transfer of lots of data?


I guess I have posted my question at the wrong place before:

So hopefully somebody in this forum can advise me on how to make my code work properly. Here's what I did:

I created a Windows service that opens a named pipe to receive data from an external application. Latter one connects and transfers up to 250 MB of data via a named pipe after it serialized a LIST of objects.

My windows service deserializes the data back into a LIST of objects, processes them and outputs the entire list into a file.

My issues are:

1.The data transfer is extremely slow! 200 MB take about 7 minutes via named pipe vs. 20 seconds if a file is used.
QUESTION: is it possible to speed up the data transfer somehow?

2.After my Windows service based processing is done I dispose the named pipe, clear the list and even call GC.Collect() but still my service is not releasing the memory.

3.Also I continue to have very high CPU load (98%) on all cores (2xQuad-core) although the service is not doing anything.
 It would be great if somebody could advise me on some of the p

provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server

after lots  of goes and back, I have the same problem but it is related to my Visual studio too. Because I can access to the same database  for new projects but when I use an existing project with a new default page I get the same error.
I am using visual studio 2005 connecting to MSSQL 2008 in server that has an instance of SQLServer express 2005 too
the code for boht new and existing project is bellow

I appricate any help


protected void Page_Load(object sender, EventArgs e)



SqlConnection cn =

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend