You can initiate a database mirroring failover from the primary server to the mirror server by executing the following statement:
ALTER DATABASE SET PARTNER FAILOVER
This statement is an alternative to specifying a preferred server, and can be used with logic that controls when ownership of the database is given to a specific database server. For example, you may want to initiate failover based on the availability of the partner server (determined by the value of the PartnerState database property), or the number of connections to the database (determined by the value of the ConnCount database property).
When this statement is executed, any existing connections to the database are closed, including the connection that executed the statement. Consequently, if the statement is contained in a procedure or event, other statements that follow it may not be executed. The permissions required to execute this statement are controlled by the -gk server option.