By your description above, it sounds like you are not using a witness server. As such, I am assuming that you are running mirroring asynchronously.For this setup, there is a 2 step process for failing the mirror over to the other server.
When running synchronously, you simply issue the partner failover command on either server:
Alter Database [Database Name] Set Partner Failover;
When running asynchronously, you need to first enable safety and then allow the databases to get synchronized. Then you can failover the mirror:
Alter Database [Database Name] Set Partner Safety Full;
...... wait
Alter Database [Database Name] Set Partner Failover;
Then after the failover is complete, you can turn safety off again:
Alter Database [Database Name] Set Partner Safety Off;
If you want to automate this process, you can query sys.database_mirroring for the database miroring state in a loop until it reaches synchronization. When I do this, I suggest using a WaitFor Delay timer to limit it to a single loop per set time interval and count the number of loops and exit the loop with an error if the loop reaches a preset count. I generally use a max counter value of 300 and a waitfor delay of 1 second which equates to 5 minutes total time to synchrnoize.