CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: SQLCMD failure

  1. #1
    Join Date
    Jan 2009
    Posts
    394

    SQLCMD failure

    I am trying to attach an ms sql database. And I am trying to use sqlcmd utillity. But anytime I try this, I got:

    Code:
    SQLCMD
    
    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..
    of course, I have tried to find the server name and instance, with:
    Code:
    SQLCMD.EXE -L
    and the answer was:
    Code:
    Servers:
        ;UID:Login ID=?;PWD:Password=?;Trusted_Connection:Use Integrated Security=?;*APP:AppName=?;*WSID:WorkStation ID=?;
    How can I find the server name and the instance name then ?

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,104

    Re: SQLCMD failure

    Victor Nijegorodov

  3. #3
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,495

    Re: SQLCMD failure

    Are the named pipes protocol enabled on sql server? They aren't by default. Search google for "sql configuration manager"

  4. #4
    Join Date
    Jan 2009
    Posts
    394

    Re: SQLCMD failure

    Quote Originally Posted by Arjay View Post
    Are the named pipes protocol enabled on sql server? They aren't by default. Search google for "sql configuration manager"
    Yes, they are enabled.

  5. #5
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,495

    Re: SQLCMD failure

    Quote Originally Posted by mesajflaviu View Post
    Yes, they are enabled.
    Are you able to connect with SSMS?

    Btw, I've used SQLCMD within PowerShell for years, but recently ran into a issue where it just would not connect to a specific server. Never could figure out the issue.

    Rather than calling SQLCMD with PowerShell, I changed the code to use the SqlServer PowerShell module.

  6. #6
    Join Date
    Jan 2009
    Posts
    394

    Re: SQLCMD failure

    In the ending is solved. Thank you all of you !

  7. #7
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,104

    Re: SQLCMD failure

    Quote Originally Posted by mesajflaviu View Post
    In the ending is solved. Thank you all of you !
    Could you share your solution?
    Victor Nijegorodov

  8. #8
    Join Date
    Jan 2009
    Posts
    394

    Re: SQLCMD failure

    I succeeded with following commands:
    Code:
    SQLCMD.EXE -S DESKTOP-YYYYYY\SQLEXPRESS
    
    CREATE DATABASE mydataabse  ON (FILENAME = 'C:\Program Files (x86)\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL\DATA\mydatabase.mdf'),   (FILENAME = 'C:\Program Files (x86)\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL\DATA\mydatabase_Log.ldf')    FOR ATTACH;
    
    GO
    after I enabled Name Pipes from Sql Server Configuration Manager.

    Thank you for your support.
    Last edited by mesajflaviu; February 15th, 2021 at 05:18 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured