Connecting to SQL Server Virtual Machine on windows Azure from another windows Azure virtual Machine or on-premise computer – Using simple Powershell Script
With
the new offering of IaaS on Azure, you can provision SQL server on windows
Azure virtual
machine.
Once SQL Server virtual machine provisioned you need to complete the
configuration steps mentioned here - http://www.windowsazure.com/en-us/documentation/articles/virtual-machines-provision-sql-server/#SSMS
Now
same link suggests using SSMS (SQL Server Management Studio) if you wish to
connect from another computer to SQL Server Azure virtual machine. What if you
don’t have SQL Server management studio installed? What if the computer you
wish to connect is Azure Virtual Machine and you don’t wish to install
management studio on it? In such scenario the best option is to use powershell
script to check the connectivity to SQL Server Azure Virtual Machine.
Below
I have written a simple powershell script which you can run from any machine to
check the connectivity with Azure Virtual Machine SQL Server.
First
open the powershell from programs menu as shown below –
Then
run following script to set execution policy. This will ask you Y or N. Select
Y to proceed.
#set
execution policy
set-executionpolicy
remotesigned
After
this copy and paste the following script in powershell window. Make sure that
you replace the Server name below yellow marked and port number, user name and
password.
function
IsSQLDBAvailable([s07ing] $SQLServer)
{
07y
{
$Connection =
New-Object System.Data.SQLClient.SQLConnection
$Connection.ConnectionS07ing = "server=mycloudservice.cloudapp.net,57500;Database=Master;User
Id=myuser;Password=mypassword;"
$Connection.Open()
return $07ue;
}
catch [System.Exception]
{
return $false;
}
}
$SSODB
= $False
while
($SSODB -eq $False)
{
$SSODB
= IsSQLDBAvailable ("mycloudservice.cloudapp.net,57500")
start-sleep -s 2
write-host "Waiting for SQL DB
..."
}
write-host
" Connected to SQL server - $SSODB `r`n"
If
the connectivity to SQL server is successful then you will receive message
as -
Connected to SQL Server
– True.
If the
machine is not able to connect to SQL Server Azure Virtual machine then you will keep receiving message
as –Waiting for SQL DB….”
This
is the simplest way by which you can check the connectivity to SQL Server on
Azure Virtual Machine. And best part is you don’t have to install SSMS.
Hope
this helps.
Cheers…
Happy
Connecting!!!
Comments
Post a Comment