Click here to Skip to main content
16,019,619 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have hosted my WCF services on IIS 7, Database is On same machine.
WCF service i have Entity framework 4.0 version.
When I am trying to perform any database operation through it,I am getting error as
"The underlying provider failed on Open."

I made changes in Application Pool
I set the Identity of Application as Local system and then now its running fine.


I want to fix this as the service will be running on net.tcp protocol.

Any solution ?
Posted
Comments
virusstorm 19-Aug-15 20:31pm    
We need more details. There should be an inner exception or a stack trace in the event viewer which has more details.
Member 11490761 20-Aug-15 1:04am    
Yes.
Stack trace :
Server stack trace:
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.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 MGSLocal.IPOS_Local.AddExchange(Response objResponse, ServiceParameters objServiceParameters)
at MGSLocal.POS_Mgtrnx_LocalClient.AddExchange(HandshakeEDCResponse objHandshakeEDCResponse, ServiceParameters objServiceParameters) in D:\Reference.cs:line 706
at MGSLocal.Clstrnxcom.ExchangeProcessing(ServiceParameters objServiceParameters) in D:\Clstrnxcom.cs:line 309
virusstorm 20-Aug-15 6:09am    
So this is the exception details from the client side, correct? I would suggest wrapping your database call on the server side in a try/catch and log the exception that takes place. Unless you setup fault exceptions correctly in WCF, you tend to loose a lot of underlying details for security reasons.
Member 11490761 20-Aug-15 6:18am    
serviceDebug includeExceptionDetailInFaults="False"

I have put the code in try catch block only, Unable to judge why i am facing this issue.
virusstorm 20-Aug-15 6:38am    
Setting that to false will not give you the details you are looking for.

Did you wrap your database operation in a try/catch and log the message so you can see what the true error is?

1 solution

If I've understand everything you put on this thread, you problem is security related.

In your web.config, you probably have connection string like this:
XML
<connectionStrings>
    <add name="MyDb" connectionString="data source=MyServer;initial catalog=MyDb;integrated security=True;" />
</connectionStrings>


Where integrated security could be replaced with Trusted_Connection. This is telling ADO.NET that you want to the account the web application is running under to connect to the database. When you create a new application pool in IIS, it uses a default account to run your web application. This account does not have permissions to access your database and which is why the connection is failing.

To fix this, you have two options. The first is setup a service account that can access the database in question. Below are a few links to help you out with that.

Accessing Database in IIS Applications[^]
Specify an Identity for an Application Pool (IIS 7)[^]
Create Database User[^]

Your next option would be to create a SQL Server account, not a network account like in the examples above. If you accepted all of the defaults during the installation of SQL Server, then it setup for Windows Authentication and would need to be changed to Mixed Authentication. This will allow for both Windows accounts and SQL Server accounts. Take a look at Creat a Login[^] on the MSDN site, specifically step 5. If you go this route, you would end up with a connection like this:
XML
<connectionStrings>
    <add name="MyDb" connectionString="data source=MyServer; initial catalog=MyDb; User Id=myUsername; Password=myPassword;" />
</connectionStrings>


The preferred method tends to be the first option I gave. This leaves the password out of the hands of the developers and helps to keep the application secure. If you go with the second option, you really should look into encrypting your configuration files to keep the password safe.

I hope this helps you out.
 
Share this answer
 
Comments
Member 11490761 20-Aug-15 7:31am    
Thanks alot.

I was mentioning integrated security = true, i removed it and now its working fine.
With my Pool Identity set as Application Pool

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900