Here's my code:

String str;
SqlConnection myConn = new SqlConnection("Server=localhost;Integratedsecurity=SSPI;database=master");             

str = "CREATE DATABASE JoesData ON PRIMARY " +
      "(NAME = JoesData, " +
      "FILENAME = 'C:\\JoesData.mdf', " +
      "SIZE = 3MB, MAXSIZE = 10MB, FILEGROWTH = 10%) " +
      "LOG ON (NAME = MyDatabase_Log, " +
      "FILENAME = 'C:\\MyJLog.ldf', " +
      "SIZE = 1MB, " +
      "MAXSIZE = 5MB, " +
      "FILEGROWTH = 10%)";

SqlCommand myCommand = new SqlCommand(str, myConn);
try
{
   myConn.Open();
   myCommand.ExecuteNonQuery();
   MessageBox.Show("DataBase is Created Successfully", "MyProgram", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (System.Exception ex)
{
   MessageBox.Show(ex.ToString(), "MyProgram", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
finally
{
   if (myConn.State == ConnectionState.Open)
   {
      myConn.Close();
   }
}

This is actually the error: enter image description here

Any idea what may be leading to this? Thanks ahead of time for just about any help.

Your database connection is failing. Look at your installation as well as your connection string.

I'd say you cannot connect with the default SQL Server instance running around the host machine.

This is often for a number of reasons.

It is not installed and began, maybe you do not have the best priviliges? It is possible to trouble with the Integrated Security, are you currently within the right server role?

It can also be more obscure, if you have localhost planned to some remote Ip in your soul hosts file but, that's not as likely.

Can it be as silly because this typo inside your connection string??

Rather than:

Server=localhost;Integratedsecurity=SSPI;database=master

try:

Server=localhost;Integrated Security=SSPI;database=master

note the SPACE between your Integrated and Security

Try supplying the Account information within the connection string