I think the listener must be running for it to refuse the connection.
Looking at your connect
string, localhost indicates a database running on your local machine, and mydsn is the SID (System identifier) of the specific database.
So, do you have an Oracle database called mydsn installed and running on your local machine?