It will become more obvious what is happening if you break that line down into segments
var x = ConfigurationManager.ConnectionStrings;
var y = x["HPDL160G62"];
var z = y.ConnectionString;
x
will not be a problem because, as you say, it's a static class so you don't need an instance.
But
y
is
null
because there is nothing in the collection that matches "HPDL160G62".
Therefore you get the error when assigning to
z
[EDIT]
The reason that there was no matching item in the collection is because the App.Config belonged to a DLL. ConfigurationManager only reads the app.config for the currently running assembly i.e. the application calling the DLL.
So the solution is to have this connection string in the App.Config for the calling application
OR
You can still have a DLL config but you will have to read it manually (I found a good example of how to do this
here[
^])