10

Regardless of what I do, I cannot get SQLCMD to work. I am trying to run a script that is 200mb+ in size and cannot be run from the sql server application so I need to do this via SQLCMD, however whenever I try to login or run the script it immediately closes.

I've followed the sqlcmd utility by msdn.

I've tried to opoen it via trusted command SQLCMD -E I get:

Sqlcmd: Error: Microsoft SQL Server Native Client 11.0 : Named Pipes Provider: Could not open a connection to SQL Server [2]. .
Sqlcmd: Error: Microsoft SQL Server Native Client 11.0 : Login timeout expired.
Sqlcmd: Error: Microsoft SQL Server Native Client 11.0 : A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online..

I've tried via explicit server, username and password declaration:

C:\Users\MyUserName\Documents>SQLCMD -S DESKTOP-1N3OD6V\SQLEXPRESS -U DESKTOP-1N3OD6V\MyUserName-P MyPassword
Sqlcmd: Error: Microsoft SQL Server Native Client 11.0 : Login failed for user 'DESKTOP-1N3OD6V\MyUserName'..
23

SQLCMD, when invoked without specifying a server name, tries to connect to a default instance on the local machine. If you don't have one, it displays the first error you are getting. Use the -S parameter to specify a server name.

To use Windows authentication, use the -E flag and you don't need to provide username or password.
Example: SQLCMD -Smyserver\myinstance -E

To use SQL Server authentication, use the -U and -P parameters to supply credentials.
Example: SQLCMD -Smyserver\myinstance -UsomeUser -PhisPassword

If you specify -U you cannot use a windows user name: this is for SQL Server logins. If you want to impersonate a different windows user, start a command prompt impersonating that user first.

Example:

  1. Open command prompt
  2. Type runas /USER:domain\username cmd
  3. Type the password for your user
  4. Run SQLCMD

You can achieve the same result right clicking the link for cmd and selecting "Run as different user..."

  • This just saved me a long night of scouring the internet. Thank you! – Rhys Johns Aug 14 '18 at 6:59
  • Spent ages trying to work this out. Thank you! – Joel Murphy Apr 3 at 9:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.