Dynamically Add and Manage Tenants Or Shard In Elastic Scale on SQL Azure for non .NET Applications

As we already discuss how to run multi tenant or shard application on the new SQL Azure Elastic scale in the Run Multi tenants applications on SQL Azure Elastic Scale for non .NET Applications blog, we want to create tenant or shard throw our application (not manually), therefore we can create new applications for the clients.

 Currently, no libraries available for non .Net applications, but in this blog we introduce an alternative that could applied in any other application to create tenants or shards.

We have developed on example available on msdn you can find it here , you can downloaded from the attachment, thus it can be used to create a new shard or tenant. What you need to do is to understand the exact syntax to use the command line.

What you need to do is to set the command line in your application and execute the suitable syntax inside.

the following shorts represent what action to do for the cmd

-OP “define the operation Add,UPDATE,DELETE default ADD”

-S “server link”

-d “shard map manager database name”

-App “sharding application name”

-U “user name”

-P “password”

-db “new database name”

-scf “sql server script file path if you would like to add file”

-tid “tenant id”

-drop “true (remove database)”

What you need to do is to set the command line in your application and execute the suitable syntax inside.

This is example to create new shard:

 

We assume we would like to execute this command in PHP script

[box type=”shadow” ]

$shellCommmandPath = ‘”C:/www/shardControlCmd.exe”‘;

$server = “https://yourserver.azure.com”;

$userName = “youruser”;

$password = “yourpassword”;

$shardManagerDatabaseName = “shardManagerDB”;

$applicationName = “app”;

$shardDatabaseName = “shardDB”;

$shardManagerDatabase = “shardManagerDB”;

$sqlPathToExecute = ‘”InitializeShard.sql”‘;

$tId = 1;

$oP =”ADD”;

$command = $shellCommmandPath . ‘ -S ‘ . $server . ‘ -d ‘ . $shardManagerDatabaseName . ‘ -App ‘ . $applicationName . ‘ -U ‘ . $userName . ‘ -P ‘ . $password . ‘ -db ‘ . $shardDatabaseName . ‘ -scf ‘ . $sqlPathToExecute . ‘ -tid ‘ . $tId.’ -OP ‘.$oP;

$shellStatus = shell_exec($command);

[/box]

Note:

– you don’t have to add sql file, this case is only when you want to create new shard and you look to execute the sql as creating tables and so on after create the database.

– when you pass existing shard data base name and manger it will just add new tenant to your database, as you can use it to open new tenants on an existing databases.

hope this will help developers on non .NET environment to create tenants automatically from their Owen applications.

 download cmd for elastic scale from here.

NO COMMENTS

LEAVE A REPLY