How to connect to SQL Server from command prompt with Windows authentication
Asked Answered
A

9

22

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.

Adjacency answered 21/3, 2014 at 6:49 Comment(0)
S
36

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!

Sarnoff answered 5/1, 2015 at 14:49 Comment(0)
S
6

Try This :

--Default Instance

SQLCMD -S SERVERNAME -E

--OR
--Named Instance

SQLCMD -S SERVERNAME\INSTANCENAME -E

--OR

SQLCMD -S SERVERNAME\INSTANCENAME,1919 -E

More details can be found here

Signor answered 21/3, 2014 at 6:53 Comment(0)
M
0

This might help..!!!

 SQLCMD -S SERVERNAME -E 
Monachism answered 21/3, 2014 at 7:4 Comment(3)
Thanks for reply, Vipin Mittal already mention this- not working :(Adjacency
Click the link I got that from here,see whether the link is helpfull to u..!!!Monachism
If I see one more person say "not working"........ EXPLAIN. What is not working? Are you getting a message? Whats the message?Christen
P
0

After some tries, these are the samples I am using in order to connect:

Specifying the username and the password:

sqlcmd -S 211.11.111.111 -U NotSA -P NotTheSaPassword

Specifying the DB as well:

sqlcmd -S 211.11.111.111 -d SomeSpecificDatabase -U NotSA -P NotTheSaPassword
Plump answered 18/10, 2017 at 10:59 Comment(0)
G
0

here is the commend which is tested

Sqlcmd -E -S "server name" -d "DB name" -i "SQL file path" 

-E stand for windows trusted

Guileful answered 22/6, 2019 at 14:34 Comment(0)
L
0

With either of 2 commands below, I could log in SQL Server 2019 Express through Windows authentication:

sqlcmd -S DESKTOP-5K4TURF\SQLEXPRESS -E
sqlcmd /S DESKTOP-5K4TURF\SQLEXPRESS /E
Lalittah answered 15/9, 2022 at 18:18 Comment(0)
A
0

This way you can connect easily:

  1. sqlcmd -S Your Server Name -U 'Login username'-P 'password'

  2. Type command: select name from sys.database and will show >1 in next line means database server connected

  3. Type go and pres enter will list all database(s)

  4. You can select any particular one and can go ahead

Alcoholize answered 19/3, 2023 at 12:0 Comment(1)
you omit the 's' at the end of sys.databasesZofiazoha
S
-1

type sqlplus/"as sysdba" in cmd for connection in cmd prompt

Sulphonamide answered 24/4, 2018 at 5:42 Comment(2)
Correct me if I'm wrong but I thought that sqlplus is an SQL client for an Oracle DB?Verger
sqlplus is ORACLEDB utility not SQL server.Chilton
C
-1

If you are running Linux, Mac OS or Windows, you can use MSSQL-CLI. Read the tutorial at https://www.mssqltips.com/sqlservertip/5298/new-interactive-command-line-tool-mssqlcli-for-sql-server/

Cognac answered 31/1, 2022 at 15:5 Comment(2)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Hem
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From ReviewGlobetrotter

© 2022 - 2024 — McMap. All rights reserved.