1

The syntax for this is explained here:

How to programatically create Sql Azure database of type Basic/Standard edition through Enity Framework code first

However, my code is implemented like this:

 public static bool CreateDatabaseIfNotExists(string connectionString, string databaseName)
        {
            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                conn.Open();

                SqlCommand cmd = new SqlCommand(
                    string.Format("SELECT * FROM sys.databases WHERE [name]=\'{0:S}\'", databaseName),
                    conn);

                cmd.CommandTimeout = int.MaxValue;

                if (cmd.ExecuteScalar() == null)
                {
                    SqlCommand cmd2 = new SqlCommand(
                        string.Format("CREATE DATABASE [{0:S}];", databaseName),
                        conn);
                    cmd2.CommandTimeout = int.MaxValue;

                    cmd2.ExecuteNonQuery();

                    return true;
                }
                else
                    return false;
            }
        }

Where exactly should I put the basic string, as I am not sure where to place it.

Community
  • 1
  • 1
Luis Valencia
  • 32,619
  • 93
  • 286
  • 506

1 Answers1

5

You specify the edition after the name of the DB:

SqlCommand cmd2 = new SqlCommand(string.Format("CREATE DATABASE [{0:S}] (SERVICE_OBJECTIVE = 'basic');", databaseName), conn);

The documentation for the syntax can be found here

Jan Engelsberg
  • 1,067
  • 6
  • 8