简体   繁体   English

如何以编程方式在Basic Edition中创建sql数据库? 在Windows Azure中

[英]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 如何首先通过Enity Framework代码以编程方式创建Basic / Standard版类型的Sql Azure数据库

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. 我不确定应该将基本字符串放在哪里,因为我不确定将其放置在哪里。

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 语法文档可以在这里找到

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM