-2

I made a WCF service and hosted in windows forms application and made a client win from application to consume that I service retrieves data from database and shows to the client by entering ID.

How can I solve it?

I have seen many null references questions in stack overflow but thy are not related to WCF.

Image of error in my code:

image of error in my code and code

Connection string in my web.config file:

this is connection string in my web.config file

Masud Jahan
  • 3,418
  • 2
  • 22
  • 35
waqar haider
  • 75
  • 10
  • 1
    Apparently you don't have a connection string by that name or something... – Jeff Mercado Jun 26 '16 at 06:51
  • it has proper connection string and works well in self hosted service but gives this error when accessed from client app – waqar haider Jun 26 '16 at 06:54
  • 1
    " i seen many null references questions in stack overflow but thy are not related to wcf " NREs are NREs, regardless of whether they occur in WCF, WinForms, ASP.NET, etc. The underlying reason for an NRE is always that you tried to perform some action on a null object (read it, call a method, etc). – Tim Jun 26 '16 at 09:38
  • 1
    If `ConfigurationManager.ConnectionStrings["foo"]` returns null while some configuration file definitely contains a `connectionStrings` entry with `name="foo"`, then you've edited the wrong configuration file. – CodeCaster Jun 26 '16 at 09:53

2 Answers2

0

Your connection string must be null. Go to your Webconfig file which is in xml format. Check whether tag has the proper connection string or it is missing. If it is missing you can add it by using this:

<connectionString>
<add name="connection_name" providerName = "provider_name" connectionString="connectionString"/>
</connectionString>

Try this it will work.

Roshni Gandhi
  • 336
  • 4
  • 13
0

You must verify that the executable that is actually running the service also has the connection string defined in app.config or web.config. Probably, when you test it you have it defined correctly, but when you run it outside the tester, the application that is actually running does not have it defined.

Eli
  • 693
  • 5
  • 12
  • i have attached pic of connection string in question which is in web.config file – waqar haider Jun 26 '16 at 08:28
  • @waqarhaider But you say that the WCF service is hosted in a Winform application. Shouldn't there be an app.config file for the application in whichever folder you are executing it? Does this config file also contain the connection string? – Eli Jun 26 '16 at 08:39
  • know app.config file does not contain connection String because it is not retrieving data by it self it is just passing ID to service and service returns the record from database – waqar haider Jun 26 '16 at 08:46
  • @waqarhaider if the service is hosted by this executable, the app.config of the executable must have the connection string. copy it from the app.config of the service and try running it. – Eli Jun 26 '16 at 08:55
  • @waqarhaider Great. If this helped, please accept the answer. Thanks. – Eli Jun 26 '16 at 20:32