If a restart of the function app results in a working situations, the basic network set-up is correct. To me this sounds like a SNAT port exhaustion. If your function is opening a connection to the database, it requires a port on the host to make the connection. When there are no more ports to open, you can get this kind of strange behaviour.
To check please do the following:
- in your Azure portal, go to the function app
- in the left column, click the 'Diagnose and solve problems'
- then click 'availability and performance'
- in the left column click 'SNAT port exhaustion'.
Now you will see a graph. I expect your graph to show an increasing line. This would indicate your code opens more ports than it closes. If this is the case, you should fix your code.
Depending on the language you use, the root cause might be hidden in some third party packages/libraries you use though.