I was trying to get powershell connect to Azure SQL Database from local. I tried the following snippet
$params = @{
'Database' = 'dbsitenamehere'
'ServerInstance' = 'instancename.database.windows.net'
'Username' = 'abcites'
'Password' = 'atbasIcpr0d'
'OutputSqlErrors' = $true
'Query' = 'SELECT * FROM Users'
}
Invoke-Sqlcmd @params
But I was getting this warning:
WARNING: Could not obtain SQL Server Service information. An attempt to connect to WMI on 'Microsoft.WindowsAzure.Commands.SqlDatabase.Types.ps1xml' failed with the following error: The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
I think, resolved the above with the solution by turning on RPC Locator service from component services link manually as shared by Hodentek @ http://hodentekmsss.blogspot.in/2014/11/how-to-overcome-error-while-importing.html >> "How to overcome error while importing the SQLPS module into Powershell?"
PS SQLSERVER:\> Import-Module “sqlps” -DisableNameChecking
PS SQLSERVER:\> cd SQL
PS SQLSERVER:\SQL> dir
MachineName
-----------
PC181578
PS SQLSERVER:\SQL> cd LocalHost
PS SQLSERVER:\SQL\LocalHost> dir
But I get the following error and stuck. I am missing something silly I guess. . Exhausted, :(
Invoke-Sqlcmd : Invalid object name 'Users'.
At line:17 char:3
+ Invoke-Sqlcmd @params
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Invoke-Sqlcmd], SqlPowerShellSqlExecutionException
+ FullyQualifiedErrorId : SqlError,Microsoft.SqlServer.Management.PowerShell.GetScriptCommand
Request some suggestions that could get me going. I feel missing missing something in my approach to get connected.
Thanks
H Bala