I'm trying to create a Azure database using a master database as a template using C#. I have the database creation working but I cannot find a way to specify the resource group for the new database.
1 Answers
0
votes
The below code snippet requires Windows Azure management class library.
If you have not installed it, run the below command in Package Manager Console
PM> Install-Package Microsoft.WindowsAzure.Management.Libraries -Pre
The code below shows how to get a subscription of cloud credentials using C#.
public static string subscriptionId = "{Your-Subscription-id}";
public static string base64EncodedCertificate = "Your-certificate-Base64-string";
static SubscriptionCloudCredentials getCredentials()
{
return new CertificateCloudCredentials(subscriptionId, new X509Certificate2(Convert.FromBase64String(base64EncodedCertificate)));
}
The code below shows how to create a SQL database using C# code.
static void Main(string[] args)
{
SqlManagementClient client = new SqlManagementClient(getCredentials());
//Server Name is your SQL Azure DataBase server name, for example:mysqlserver001
client.Databases.Create("{Server-Name}", new Microsoft.WindowsAzure.Management.Sql.Models.DatabaseCreateParameters()
{
Name = "SqlDBTest",
MaximumDatabaseSizeInGB = 1,
CollationName = "SQL_Latin1_General_CP1_CI_AS",
Edition="Web"
});
Console.ReadLine();
}