Luis Valencia
Luis Valencia

Reputation: 33978

How to create a sql database in Basic edition programmatically? in Windows Azure

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.

Upvotes: 1

Views: 1176

Answers (1)

Jan Engelsberg
Jan Engelsberg

Reputation: 1087

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

Upvotes: 5

Related Questions