[英]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. 我不确定应该将基本字符串放在哪里,因为我不确定将其放置在哪里。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.