none
Cannot Access SQL Server From Command Prompt

    Question

  • Hi,

    My SQL Server Express 2005 is running. I can see it running from the "SQL Server Management Studio Express", as well as from the Visual Studio 2010.

    And here is the ConnectionString:

    ConnectionString="Data Source=localHost;Initial Catalog=Pubs; Integrated Security=SSPI"

    However, when I try to access it from a Command Prompt, including Visual Studio Command Prompt, even when I "run as administrator", by typing "SqlCmd -S localhost\SQLEXPRESS", it fails with the following message:

    Sqlcmd: Error: Connection failure. SQL Native Client is not installed correctly. To correct this, run SQL Server Setup.

    I will appreciate very much if someone can help me with this.

    Thanks so much,

    Goldstar Lee

     

     


    Goldstar Lee

    Wednesday, October 16, 2013 5:04 PM

All replies

  • ConnectionString=Data Source=localHost;Initial Catalog=Pubs; Integrated Security=SSPI

    ....  by typing "SqlCmd -S localhost\SQLEXPRESS", it fails with the following message:

    Hello Lee,

    you are using 2 different SQL Server server name:
    localhost
    localhost\SQLEXPRESS
    so which one is the correct one? if "localhost" works in Visual Studio and SSMS, then use it also for SqlCmd!


    Olaf Helper

    [ Blog] [ Xing] [ MVP]

    Wednesday, October 16, 2013 5:18 PM
  • Hi Olaf Helper,

    I use "localhost\SQLEXPRESS", because I am using SQL Express.


    Goldstar Lee

    Wednesday, October 16, 2013 5:33 PM
  • Hi Olaf,

    Thanks for pointing out that discrepancy.

    Earlier I gave you a wrong answer, ie, I said that mine was an SQLEXPRESS. Actually it is a full version SQL Server. Therefore it should use localhost, NOT localhost\SQLEXPRESS.

    I corrected that mistake, so I type "SqlCmd -S localhost" on the command prompt.

    However, I still got the same error message:

    Sqlcmd: Error: Connection failure. SQL Native Client is not installed correctly. To correct this, run SQL Server Setup.

    I appreciate if you could help further.


    Goldstar Lee

    Thursday, October 17, 2013 2:01 AM
  • Sqlcmd: Error: Connection failure. SQL Native Client is not installed correctly. To correct this, run SQL Server Setup.


    Then you may re-install the SQL Native Client, you can get it as a separate installer from Feature Pack for Microsoft SQL Server 2005 - December 2008 => sqlncli_x??.msi

    Olaf Helper

    [ Blog] [ Xing] [ MVP]

    Thursday, October 17, 2013 3:22 AM
  • Hi Olaf,

    Thanks so much for your suggestion. I would like to ask you 2 more questions though.

    (1) I just want to access my SQL Server (2005) from a Command Prompt (by typing "SqlCmd -S localhost"). Why do I need an SQL Native Client ? What does it do ? Does it translate what I type on the Command Prompt into the language which the SQL Server can understand ?

    (2) After downloading the SQL Native Client from the link you suggested, what else should I do to get "SqlCmd -S localhost" working on the Command Prompt ?


    Goldstar Lee

    Thursday, October 17, 2013 11:54 PM
  • Why do I need an SQL Native Client ? What does it do ?

    Hello,

    It's the data access component (including OleDB/ODBC) to communicate via TDS over the network with SQL Server.

    Just install/repair the native client and SqlCmd should work then.


    Olaf Helper

    [ Blog] [ Xing] [ MVP]

    Friday, October 18, 2013 6:26 AM
  • Hi Olaf,

    I could guess what you meant, but I just want to make sure.

    Should I choose: sqlncli_ia64.msi, sqlncli_x64.msi, sqlncli.msi ?

    Thanks again.


    Goldstar Lee

    Friday, October 18, 2013 2:45 PM
  • Hi Olaf,

    I asked my previous question because I am confused:

    My computer processor is Intel Core. However, its processor architecture is AMD64 (from command prompt). So which one should I use for the download ?


    Goldstar Lee

    Friday, October 18, 2013 3:03 PM
  • I checked further, AMD64 is actually x86-64, which is compatible only with x64 OS. And my OS is Window 7, which precludes ia64.

    So I think I should choose sqlncli_x64.msi.


    Goldstar Lee

    Friday, October 18, 2013 3:40 PM
  • It doesn't work. When installed, it says that it failed because I have a higher version of the product.

    Upon checking, I do have "Microsoft SQL Server Native Client" installed on my computer. It doesn't say what year, but I suppose it is a version of 2005, albeit higher version than the one you suggested, hence it collides.

    I use SQL Server for my ASP.NET-based web application, with ADO.NET for DB operations.

    My questions are: (1) why my installed SQL Native Client works for ADO.NET, but not for SqlCmd ? Does it mean it misses some functionality for SqlCmd from the command prompt ? (2) What is a higher version of SQL Native Client than the one you suggested ?

    Thanks.


    Goldstar Lee

    Tuesday, October 22, 2013 4:42 PM