38

I just installed SQL Server 2008, and I wanted to use the command editor to execute queries.

To do that I opened the command prompt, and I typed

Sqlcmd -S Serverinstance

but I got an error saying :

Named Pipes Provider: Could not open a connection to SQL Server [53].
Sqlcmd : erreur : Microsoft SQL Server Native Client 10.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..
Sqlcmd : erreur : Microsoft SQL Server Native Client 10.0 : Login timeout expired

What should I do to get it connected to the server so I can proceed?

Thank you :D.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Zakaria Marrah
  • 755
  • 6
  • 15
  • 28
  • You say you're doing `SqlCmd -S Serverinstance`. For a named instance on your local machine, that should be `SqlCmd -S .\`. Is that what you're using? If you're just giving an instance name, it will think you're specifying a server name instead. – Damien_The_Unbeliever Jan 07 '13 at 14:56

3 Answers3

66

(This one is going to sounds silly) my problem was that I wasn't using capital 'S'

Eg:

C:\> SQLCMD -S localhost\sqlexpress
Christian Payne
  • 7,081
  • 5
  • 38
  • 59
13

You need to either use the integrated-security approach of using your Windows credentials to connect to SQL Server by specifying -E as an option:

C:\> SQLCMD -S Serverinstance -E

or then you need to define a user/password set to achieve a SQL Server login:

C:\> SQLCMD -S Serverinstance -U (login in) -P (password)

All the many SQLCMD parameters are well-documented on MSDN SQL Server Books Online!

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
0

The server you are specifying cannot be found or is not accessible. so either the server is wrong (have you spelt it correctly) or you are not specifying it correctly or it is not accessible from your machine.

After you've got that right, you will need to specify a username/password or a -E command qualifier for a Trusted Connection. You may also need to specify the database with a -d qualifier.

You can get help by typing

Sqlcmd -?
Ciarán
  • 3,017
  • 1
  • 16
  • 20
  • Thank you for your answer, the server is properly configured, i know that because i am working with sql server management studio, and it's working just fine, but for me to acquire sql Server queries i want to write the queries in the command prompt so i can learn it clearly :D Can you give me the command syntax on how to connect to the server ? please – Zakaria Marrah Jan 07 '13 at 14:42
  • What is your server name? Do you have trusted access or do you use a username/password to connect to the database? What is your database name? – Ciarán Jan 07 '13 at 14:45
  • The instance name is 'ZAKINSTANCE'?, and to access the database i use a username: 'my account name', and the password is 'the pzassword of my account' – Zakaria Marrah Jan 07 '13 at 14:50
  • 2
    Well then sqlcmd -s ZAKINSTANCE -U accountname - P password should work, then specify the -d databasename as well. BTW, something called `ZAKINSTANCE` sounds like an instance on a server. This is probably NOT your server name. What do you see as the server name in SSMS in the object Explorer? – Ciarán Jan 07 '13 at 14:55
  • Thank you, you are right, i changed the Server name by adding the name of the instance to the server name, like: -S ServerName\Instance name, but i got another error : couldn't open a session to 'My account name' what should i do? – Zakaria Marrah Jan 07 '13 at 15:05
  • Try putting double quotes around your username and password – Ciarán Jan 07 '13 at 15:11