Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 556
Abdullah Leghari Avatar asked Mar 21 '14 06:03

Abdullah Leghari


2 Answers

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!

like image 184
Pjarenee Avatar answered Sep 22 '22 19:09

Pjarenee


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

like image 38
Vipin Mittal Avatar answered Sep 22 '22 19:09

Vipin Mittal