c# - 如何以编程方式在Basic版本中创建sql数据库?在 Windows Azure 中

标签 c# sql azure azure-sql-database azure-elastic-scale

其语法解释如下:

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

但是,我的代码是这样实现的:

 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;
            }
        }

我到底应该把基本字符串放在哪里,因为我不确定把它放在哪里。

最佳答案

您在数据库名称后指定版本:

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

可以找到该语法的文档 here

关于c# - 如何以编程方式在Basic版本中创建sql数据库?在 Windows Azure 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31437097/

相关文章:

c# - 在数据集中寻找字段 C#

c# - 在 C# 中使用 Revit API 提示用户回答 bool 选择

php - MySQL错误: This command is not supported in the prepared statement protocol yet

mysql - 加入群组的方式是?

Azure 逻辑应用 - 通过 powershell 更新 Blob API 连接

c# - 如何在 C# 中完成作用域变量重置?

c# - 你如何询问一个数组是否包含一个特定的类?

mysql - INSERT ... ON DUPLICATE KEY UPDATE 在我的数据库中不起作用

azure - 在 Azure 数据工厂中使用本地数据网关

sql-server - Entity Framework Core 与 ASP.NET Core Web API 和 SQL Server (+ Xamarin.Forms)