Search code examples
azure-sql-databasessmssqlcmd

SQLCMD from SSMS is not working; connecting to Azure SQL Database


Running this from my SQL Server Management Studuio (SSMS) connecting to Azure sql database. I am using SQLCMD mode of SSMS.

:Connect -S taiobdemo1.database.windows.net -d taiobcustomer -U sqlusername -P strongpw

Getting this error:

A fatal scripting error occurred. Incorrect syntax was encountered while parsing :Connect.


Solution

  • The :connnect SqlCmd command does not allow you to specify a target database. You'll always connect to your default database. So it's pretty useless in Azure SQL Database, as you'll be connected to Master and won't be able to switch.

    eg

    :Connect xxxx.database.windows.net  -U someuser -P xxxx
    select db_name()
    

    Will always output master