Introducing Radical.sh

Forget Code launches a powerful code generator for building API's

Connecting SQL SERVER with Initial catalog in C#

You can also supply your database initially by initial catalog option.
  1. private void btnCheckConnection_Click(object sender, EventArgs e)
  2. {
  3. SqlConnection conn = new SqlConnection();
  4. conn.ConnectionString = "data source=my-PC;integrated security=SSPI;initial catalog=ForgetCode";
  5. try
  6. {
  7. conn.Open();
  8. MessageBox.Show("Connection was successful");
  9. }
  10. catch
  11. {
  12. MessageBox.Show("Failed to connect to data source");
  13. }
  14. finally
  15. {
  16. conn.Close();
  17. }
  18. }


Here, ForgetCode is set as default database.