Connect to sql box via cmdshell

  • Hello,

    I am trying to connect to a SQL box via cmdshell and not having much luck. I am able to run a query for cmdshell but I want my cmd prompt to already be connected so I can simply type "select * from table" without the connection string.

    This is what I have so far...

    sqlcmd -S SERVER -d DB -E

    I want cmdline to reflect the SQL server and not my local machine.

    C:\Users\12345678>

    SQL Server BOX>

    The are no problems, only solutions. --John Lennon

  • Lord Slaagh - Thursday, January 12, 2017 1:39 PM

    Hello,

    I am trying to connect to a SQL box via cmdshell and not having much luck. I am able to run a query for cmdshell but I want my cmd prompt to already be connected so I can simply type "select * from table" without the connection string.

    This is what I have so far...

    sqlcmd -S SERVER -d DB -E

    I want cmdline to reflect the SQL server and not my local machine.

    C:\Users\12345678>

    SQL Server BOX>

    I'm guessing that your question is 'How do I change the text of the prompt?' Is that correct?

    The absence of evidence is not evidence of absence.
    Martin Rees

    You can lead a horse to water, but a pencil must be lead.
    Stan Laurel

  • If you want Powershell/CMD to go straight to sqlcmd, you could make it a shortcut with the command passed through

    For example:
    C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command "sqlcmd -S MySQLServer -d TestDB -E"

    Thom~

    Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
    Larnu.uk

  • Phil Parkin - Thursday, January 12, 2017 1:46 PM

    Lord Slaagh - Thursday, January 12, 2017 1:39 PM

    Hello,

    I am trying to connect to a SQL box via cmdshell and not having much luck. I am able to run a query for cmdshell but I want my cmd prompt to already be connected so I can simply type "select * from table" without the connection string.

    This is what I have so far...

    sqlcmd -S SERVER -d DB -E

    I want cmdline to reflect the SQL server and not my local machine.

    C:\Users\12345678>

    SQL Server BOX>

    I'm guessing that your question is 'How do I change the text of the prompt?' Is that correct?

    yes, thanks!

    The are no problems, only solutions. --John Lennon

  • Lord Slaagh - Friday, January 13, 2017 8:28 AM

    Phil Parkin - Thursday, January 12, 2017 1:46 PM

    Lord Slaagh - Thursday, January 12, 2017 1:39 PM

    Hello,

    I am trying to connect to a SQL box via cmdshell and not having much luck. I am able to run a query for cmdshell but I want my cmd prompt to already be connected so I can simply type "select * from table" without the connection string.

    This is what I have so far...

    sqlcmd -S SERVER -d DB -E

    I want cmdline to reflect the SQL server and not my local machine.

    C:\Users\12345678>

    SQL Server BOX>

    I'm guessing that your question is 'How do I change the text of the prompt?' Is that correct?

    yes, thanks!

    I don't believe you can do it in the command prompt, however, using powershell the prompt will display the server name.
    http://www.sqlhammer.com/t-sql-command-line-options-part-5-sqlps/

    Thomas LiddleSQL Server AdministratorVideo Blog - YouTubeWeb Blog - www.thomasliddledba.comTwitter - @thomasliddledbaFacebook - @thomasliddledba

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply