This might not be the most elegant or efficient way to do it, but it does work, This code first tries connecting with windows authentication and if that fails it will try SQL authentication. In essence it works on the same principal as your question.
All you will need to do is use the two different connection strings at different stages within the try catches.
public void Connect()
{
try
{
string connectionString = "Data Source='" + ServerAdrress.Text + "';Initial Catalog='" + DatabaseSelection.SelectedItem.ToString() + "';Integrated Security=SSPI;";
string SQLconnectionString = "Data Source='" + ServerAdrress.Text + "';Initial Catalog='" + DatabaseSelection.SelectedItem.ToString() + "';Persist Security Info=True;User ID='" + ConnectionUser.SelectedItem.ToString() + "';Password='" + lblPassword.Text + "'";
try
{
conn = new SqlConnection(connectionString);
conn.Open();
}
catch (Exception ex)
{
try
{
conn = new SqlConnection(SQLconnectionString);
conn.Open();
}
catch (Exception)
{
MessageBox.Show(ex.Message);
conn.Close();
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
Hope this helps.