Lui*_*cia 1 c# sql azure azure-elastic-scale azure-sql-database
这里解释了这个的语法:
如何首先通过Enity Framework代码以编程方式创建基本/标准版类型的Sql Azure数据库
但是,我的代码实现如下:
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;
}
}
Run Code Online (Sandbox Code Playgroud)
我应该把基本字符串放在哪里,因为我不知道放在哪里.
小智 5
您可以在DB名称后指定版本:
SqlCommand cmd2 = new SqlCommand(string.Format("CREATE DATABASE [{0:S}] (SERVICE_OBJECTIVE = 'basic');", databaseName), conn);
Run Code Online (Sandbox Code Playgroud)
可以在此处找到语法文档
| 归档时间: |
|
| 查看次数: |
869 次 |
| 最近记录: |