My pi is connected to two different networks, one by ethernet and one by a wifi dongle. The ethernet network is not connected to the internet but the wireless one is. The pi automatically uses ethernet to try to access the internet and obviously fails. How can I force it to use wifi?
Your default route most likely points the traffic to that wired interface's default gateway. You may see the routes by issuing for example
ip route show, also simple
route shows the details. So, you'll have to change the default route to wireless' interfaces gateway and add a another (static) route for the internal (wired) network traffic.
Hopefully this helps.