sqlcmd Connection error

Posted on 2008-11-03
Last Modified: 2012-05-05
I have a .sql file as below:
USE dan_test
SELECT     uname, upwd
FROM         dbo.dan
I am trying to run this from the Vista command line with the following command:
sqlcmd -S DANHP\SQLEXPRESS -i C:\ftp\test.sql -o C:\ftp\output.rpt

the output file returns the following error:

HResult 0xFFFFFFFF, Level 16, State 1
SQL Network Interfaces: Error Locating Server/Instance Specified [xFFFFFFFF].
Sqlcmd: Error: Microsoft SQL Native Client : An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections..
Sqlcmd: Error: Microsoft SQL Native Client : Login timeout expired.

I have checked the server settings and Allow remote connections to this server is enabled and I am using mixed mode authentication and am going to use windows authentication.
When I get this working I will create a bat file to run in windows scheduler.

Thanks is adance for any help.
Question by:panhead802
    LVL 2

    Expert Comment

    Some things to check:
    1.  The syntax of the server\instance name of DANHP\SQLEXPRESS is correct
    2.  The server instance is running (to be sure it's running, execute the following from a command line:  net start MSSQL$SQLEXPRESS)
    3.  Remote connections to the server\instance are allowed for both TCP/IP AND Named Pipes

    Author Comment

    I ran net start MSSQL$SQLEXPRESS and got the error access is denied.

    I have the SSMSE running DANHP\SQLEXPRESS is the server\instance name

    the only way I know to check the remote connections is through the SSMSE and in the server properties under connections the check box for allow remote connections is checked. I am not sure if it is for Named Pipes.
    LVL 2

    Expert Comment

    Run a trace - find out what the login is trying to authenticate as:
    1.  Close all DB connections
    2.  Open SQL Mgmt Studio - do not connect to a server.
    3.  In Sql Mgmt Studio, open Tools -> SQL Profiler
    4.  Click New Trace
    5.  Run your sqlcmd from the command line
    6.  Post your results here

    Author Comment

    I am using SQL 2005 Express, and SQL Server MAnagement Studio Express. SQL Profiler is not there.
    LVL 2

    Accepted Solution

    Try forcing a valid username/password that you know works by using the following syntax in your cmd line:
    sqlcmd -s DANHP\SQLExpress -u username -p password -i C:\ftp\test.sql -o C:\ftp\output.rpt

    I believe if you leave out the -p parameter that you get prompted for a password, which is not a bad idea because the password will be sent in plain text and will appear in the command window for the world to see so be careful ;)
    Let me know how it goes.

    Author Closing Comment

    Issue was with the SQL Server permissions on my Vista machine. I tested as you suggested on my 2K3 Server and all is well with the world thanks for the assistance.


    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Suggested Solutions

    Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
    Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
    Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
    Viewers will learn how the fundamental information of how to create a table.

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now