how to connect to another database in wordpress

Look at the order of the constructor arguments in the documentation:

string $dbuser, string $dbpassword, string $dbname, string $dbhost

You’ve got the arguments in the wrong order. Move the host to the end:

$newconnection= new wpdb("username","password","databasename","localhost");