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.

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.