Can I query from two databases if my web application is connected to one database?
You need to add DB2 as a linked server on your DB1 instance.
Once created, then you can specify [LinkedServer].[Database].[schema].[Table] to query the objects on that server. Other than linked servers, there is no other way for a connection to discover and connect to another server(even if you have access) for security reasons. If you create a linked server, you are specifying a connection that server DB1 can establish and query DB2, all from BD1, not from the client.

Hope that helps.
How to create a linked server in MSSQL