none
SQLCMD not able to connect to SQL Server RRS feed

  • Question

  • Hi All,

    I am new to MSSQL, i wanted to execute my stored procedures to my remote DB server, so I have planned to use sqlcmd utility because i dont have ssms installed in my machine. So I have downloaded the utility and installed in my machine. I am able to connect to remote DB server using

    <style type="text/css"><!--td {border: 1px solid #ccc;}br {mso-data-placement:same-cell;}--></style>"}" style="font-size:10pt;font-family:Arial;">sqlcmd -S <ComputerName/IP>

    "}" style="font-size:10pt;font-family:Arial;">but when I try to run sqlcmd on the command prompt, its not connecting to sqlcmd prompt, rather its throwing the following error.

    "}" style="font-size:10pt;font-family:Arial;">

    I have disabled my firewall setting and checked, same case. 

    I wanted to automate the same through Jenkins, Can someone help me to fix this. 

    Regards,

    Dhamodharan.

    Monday, July 15, 2019 8:19 AM

Answers

  • Hi Olaf,

    Thanks for the support, I was running the script file only which results in the same error. Now I have modified my script file and passing the credentials over the script itself. Now its working.

    Regards,

    Dhamodharan

    • Marked as answer by DhamodharanD Monday, July 15, 2019 10:49 AM
    Monday, July 15, 2019 10:38 AM

All replies

  • In your screenshot I can see, that you didn't address the server using the -S parameter

    Olaf Helper

    [ Blog] [ Xing] [ MVP]

    Monday, July 15, 2019 8:33 AM
    Moderator
  • Is that default or named instance SQL SEVRER?

    https://stackoverflow.com/questions/14815297/microsoft-sql-server-native-client-10-0-login-timeout-expired


    Best Regards,Uri Dimant SQL Server MVP, http://sqlblog.com/blogs/uri_dimant/

    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting: Large scale of database and data cleansing
    Remote DBA Services: Improves MS SQL Database Performance
    SQL Server Integration Services: Business Intelligence


    Monday, July 15, 2019 8:36 AM
    Moderator
  • Hi Olaf Helper,

    Thanks for your revert... But I wanted this to be executed as script. I have a batch file which contains my server and db detail. 

    my script is

    ===========================================

    @echo off
    setlocal enabledelayedexpansion
    set servername=<mydb-IP>
    set dbname=<mydb-name>
    set spath=C:\MSSQL\Sps
    set hr=%time:~0,2%
    if "%hr:~0,1%" equ " " set hr=0%hr:~1,1%
    set logfilepath= %spath%\output_%date:~-4,4%%date:~-10,2%%date:~-7,2%_%hr%%time:~3,2%%time:~6,2%.log
    set cmd='dir %spath%\*.sql /b/s'
    FOR /f %%G IN (%cmd%) DO (
    echo *****PROCESSING %%G FILE*****
    echo *****PROCESSING %%G FILE***** >> %logfilepath%
    SQLCMD -S%servername% -E -d%dbname% -b -i%%G >> %logfilepath%
    IF !ERRORLEVEL! NEQ 0 GOTO :OnError
    )
    GOTO :Success

    ==================================================

    I am able to run the script in my local machine which have test sql server.

    Monday, July 15, 2019 8:42 AM
  • Then you have to start the Batch file, not SqlCmd directly.

    Olaf Helper

    [ Blog] [ Xing] [ MVP]

    Monday, July 15, 2019 8:51 AM
    Moderator
  • Hi Olaf,

    Thanks for the support, I was running the script file only which results in the same error. Now I have modified my script file and passing the credentials over the script itself. Now its working.

    Regards,

    Dhamodharan

    • Marked as answer by DhamodharanD Monday, July 15, 2019 10:49 AM
    Monday, July 15, 2019 10:38 AM
  • Hello, 

    Use ODBC manager to create System or User data source name. make connection tested and works.

    When you get connected to the server - use the name of the connection  or the same connection parameters to connect.

    About respond - most likely there are no SQL server, SQL server didn't have default instance or everything are fairwalled somewhere, including all router and remote host. Try to check by using TELNET (telnet server 1433). 


    Sincerely, Highly skilled coding monkey.

    Monday, July 15, 2019 10:47 AM