Displaying data from another database

And there is your issue — WordPress does need to understand URL. Otherwise it is indeed 404 because it doesn’t correspond to anything WP “knows”.

You need to create that understanding, for example by using Rewrite API. Also since your data is external and isn’t really a part of WP context, you will probably need to override 404 decision as well in the end.