I have a WCF service hosted in IIS 6 on my development Server2003 machine
that connects to it's sql server DB successfully. That same service won't
connect to the same database on a target Server2003 system. However a Forms
Application, using identical code and connectionstring will connect
successfully on the target machine.
I'm also having a problem with a normal website on that same target
connecting with SQL Server.
So, I seems that stuff hosted in IIS on this Target server can't connect
with sql server.
What could cause this? The error is pasted below.
Thanks,
Gary
System.ServiceModel.FaultException`1 was unhandled
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: Named Pipes Provider,
error: 40 - Could not open a connection to SQL Server)"
Source="mscorlib"
StackTrace:
Server stack trace:
at
System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(Message
reply, MessageFault fault, String action, MessageVersion version,
FaultConverter faultConverter)
at
System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime
operation, ProxyRpc& rpc)
at System.ServiceModel.Channels.ServiceChannel.Call(String action,
Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[]
outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.Call(String action,
Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[]
outs)
at
System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage
methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage
message)
Exception rethrown at [0]:
at
System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage
reqMsg, IMessage retMsg)
at
System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&
msgData, Int32 type)
at VtaxDSClient.VT.IVtaxDataService.UOrders(String columnname, Object
value, Object key)
at VtaxDSClient.VT.VtaxDataServiceClient.UOrders(String columnname,
Object value, Object key) in C:\Documents and Settings\Administrator\My
Documents\Visual Studio 2008\Projects\VtaxDSClient\VtaxDSClient\Service
References\VT\Reference.cs:line 50
at VtaxDSClient.Form1.btnUpdate_Click(Object sender, EventArgs e) in
C:\Documents and Settings\Administrator\My Documents\Visual Studio
2008\Projects\VtaxDSClient\VtaxDSClient\Form1.cs:line 24
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons
button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&
m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd,
Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG&
msg)
at
System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at
System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32
reason, ApplicationContext context)
at
System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason,
ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at VtaxDSClient.Program.Main() in C:\Documents and
Settings\Administrator\My Documents\Visual Studio
2008\Projects\VtaxDSClient\VtaxDSClient\Program.cs:line 18
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[]
args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence
assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
WenJun Zhang[msft] - 07 Oct 2008 09:48 GMT
Hi Gary,
The error in the exception is a general one of SQL connection failure(see
article below). Since your winform application works fine, I suspect the
problem is most likely on user credential or permission part due to winform
application run under your current logon context(generally it's an admin
account) but sites/WCF services hosted on IIS run under specific identities.
Named Pipes Provider, error: 40 - Could not open a connection to SQL Server
(Microsoft SQL Server, Error: XXX)
http://blogs.msdn.com/sql_protocols/archive/2007/05/16/named-pipes-provider-
error-40-could-not-open-a-connection-to-sql-server-microsoft-sql-server-erro
r-xxx.aspx
I wonder if you've put the WCF service and the web site into a custom
application pool(web site/vdir's property->home/virtual directory
tab->application settings) and specified a custom account as the pool's
identity(application pool property->identity tab)? By default, the build-in
identity account is local Network Service which shouldn't have access to
the remote SQL. You can change it to a domain account or a local account
exists on both IIS and SQL(with the same username and password).
Furthermore, please note the custom account need to be added to IIS_WPG
group and granted with the following group policy permissions to make it a
valid IIS worker process identity:
Adjust memory quotas for a process
Replace a process level token
For your reference:
Default permissions and user rights for IIS 6.0
http://support.microsoft.com/?id=812614
I hope the information above will be of help. Please update here if the
problem still persists.
Have a great day.
Sincerely,
WenJun Zhang
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:
msdnmg@microsoft.com.
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 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 or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://support.microsoft.com/select/default.aspx?target=assistance&ln=en-us.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
GaryDean - 09 Oct 2008 01:04 GMT
WenJun,
We solved the problem...
The database is a local database. All Websites hosted in IIS 6 and all
Forms Applications could connect successfully using the same user connection
string. The problem was that just the WCF service could not connect and it
was being hosted by the same IIS 6 that was hosting the websites.
Apparently, if a database connection is coming from a hosted WCF service, it
is considered a remote connection. Of course the "Allow remote connections
to this server was checked in the database instance properties. However the
database was not configured to allow remote TCP/IP and Named Pipes
connections. I found that by using the following procedure that Charles
Wang gave me . . .
1. Check if remote connections for both TCP/IP and Named Pipes is enabled
Click Start->All Programs->Microsoft SQL Server 2005->Configuration
Tools->SQL Server Surface Area Configuration->Surface Area Configuration
for Services and Connections, expand <instance name>->Database Engine and
select Remote Connections, then you can find "Local and remote connections"
at the right pane, select "Using both TCP/IP and named pipes" if it is not
selected.

Signature
Regards,
Gary Blakely
Dean Blakely & Associates
www.deanblakely.com
> Hi Gary,
>
[quoted text clipped - 69 lines]
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
WenJun Zhang[msft] - 10 Oct 2008 03:15 GMT
Gary,
Glad to see the problem has been resolved from SQL side.
Have a nice weekend.
Sincerely,
WenJun Zhang
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:
msdnmg@microsoft.com.
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 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 or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://support.microsoft.com/select/default.aspx?target=assistance&ln=en-us.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
WenJun Zhang[msft] - 09 Oct 2008 11:04 GMT
Hi Gary,
Just want to check how the issue is going?
Thanks.
Sincerely,
WenJun Zhang
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:
msdnmg@microsoft.com.
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 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 or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://support.microsoft.com/select/default.aspx?target=assistance&ln=en-us.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.