sqlsql-serverdatabasesql-server-2008command-prompt

How to connect to SQL Server from command prompt with Windows authentication


How can I connect to SQL Server from command prompt using Windows authentication?

This command

Sqlcmd -u username -p password 

assumes a username & password for the SQL Server already setup

Alternatively how can I setup a user account from command prompt?

I've SQL Server 2008 Express on a Windows Server 2008 machine, if that relates.


Solution

  • You can use different syntax to achieve different things. If it is windows authentication you want, you could try this:

    sqlcmd /S  /d  -E
    

    If you want to use SQL Server authentication you could try this:

    sqlcmd /S  /d -U -P 
    

    Definitions:

    /S = the servername/instance name. Example: Pete's Laptop/SQLSERV
    /d = the database name. Example: Botlek1
    -E = Windows authentication.
    -U = SQL Server authentication/user. Example: Pete
    -P = password that belongs to the user. Example: 1234
    

    Hope this helps!