Questions tagged [sqlcmd]

SQLCMD is Microsoft SQL Server's command line utility that allows you execute T-SQL commands from a command prompt.

Filter by
Sorted by
Tagged with
1
vote
1answer
569 views

Update mysql DB when data has a single quote with Dynamic values

I am writing data to mysql DB from my linux machine using sqlcmd. My script is updating the data Dynamically based on the employee number. I have a situation where the the CN attribute might have ...
3
votes
1answer
1k views

SQLCMD -L Returns Bizarre Response Instead of Server List

I have a server with three installed SQL Server 2014 instances with Service Pack 1 (build number is 12.0.4213.0) installed. When I run SQLCMD -L on the server I am getting the bizarre response below. ...
2
votes
2answers
35 views

using SQLCMD to export/extract data withot trailing spaces

I am trying to extract data from some of my tables using sqlcmd utility as SSMS does not generate appropriate csv-s for me. My issue: all csv extract includes trailing spaces according to table ...
0
votes
1answer
182 views

Copy last modified files from network path into SQL server box and rename them using Agent job

I have to copy latest backup from a network path and bring that to my SQL server physical drive for restore, I have to do that using agent job. This is what i am doing. Created a SQL server agent ...
5
votes
1answer
3k views

Can not connect to SQL Server from Ubuntu sqlcmd client

I'm trying to connect to a SQL Server Express server from a Linux Ubuntu 16.04 computer. I Installed all SQL commad line utilities for the linux machine and follow instructions from Microsoft SQL ...
2
votes
1answer
113 views

Verify failed SQL Server connections to instances on a given server and email them

I am trying to monitor the SQL Server instances on standalone server / cluster server. I would like to setup something from commandline to check for connectivity to each SQL Server instance on the ...
0
votes
1answer
43 views

sqlcmd returns Msg 701 when importing +10MB queries

I have a powershell script that exports data from DBF files, saves them as .SQL files and then imports the SQL files into MS SQL 2016 using the sqlcmd command. There's one SQL file per table in my ...
1
vote
1answer
541 views

Linux sqlcmd connecting to Windows Sql Server using kerberos

I'm pretty sure I am going to have to expand upon this a bit as I am new, and my question is probably not clear. I have an Active Directory environment that includes a Microsoft SQL Server running ...
18
votes
2answers
25k views

Can I enable SQLCMD mode from inside a script?

Is there something like a directive which I can use in a script to force SSMS to enable/disable SQLCMD mode?
1
vote
4answers
3k views

help in connecting the sql server 2017 developer edition [closed]

I have installed the sql server 2017 for non production environment in my PC. It has installed successfully. when connect using sqlcmd it was throwing an error login failed for login sa. it didn't ...
0
votes
2answers
78 views

How to find a list of local MS SQL Servers?

I looked at How can I determine installed SQL Server instances and their versions? already but CMD returns nothing: C:\Windows\system32>sqlcmd -L C:\Windows\system32> But when using Visual ...
1
vote
1answer
71 views

Lost SQL credentials and unable to connect to SQL via SQLCMD

I have a machine running SQL 2014 but have neither the windows authentication or sa authentication details due to mismanagement of a previous support team. Having tried logging in to SQL Management ...
2
votes
3answers
3k views

Is there a way to tell SQLCMD not to output rows to text or a file?

I am testing the behavior of a SELECT statement that returns 170,000,000 rows using SQLCMD. My goal is to cut out the time spent receiving the result-set on the client end (the time the process shows ...
2
votes
2answers
184 views

:!!echo command not working from sqlcmd

I have a sql script file which is executed from a batch file and is supposed to execute some sql scripts and write errors and output to files. Here is an example of how the script file looks like: :...
9
votes
2answers
5k views

Variable inside another variable in SQLCMD mode

Trying to tidy up my SQL script with SQLCMD mode and I ran into an issue: :setvar db_suffix "some_suffix" :setvar some_db "some_db_$(db_suffix)" print 'some_db: $(some_db)' The output of that is: ...
0
votes
0answers
165 views

Remove (XX.. rows affected) from SQLCMD output to file [duplicate]

Using SQLCMD with -o to file. How to get rid of the (XX... rows affected) message at the end for a clean output?
1
vote
2answers
641 views

With LocalAdmin become sysadmin SQL Server

I am a local Admin on my machine. My account wasn't added when SQL Server was installed, and I don't want to have to reinstall SQL Server. It worked until I tried to log and run the commands via ...
3
votes
3answers
4k views

How can I output more than 256 characters to a file?

I am using the following command to write the output from a stored procedure to a file for further processing: DECLARE @shellCommand VARCHAR(2000) SET @shellCommand = 'SQLCMD -S ' + @@SERVERNAME + ' -...
20
votes
4answers
27k views

SQLCMD command is not able to insert accents

I am trying to run sqlcmd.exe in order to setup a new database from command line. I am using SQL SERVER Express 2012 on Windows 7 64 bits. Here's the command I use: SQLCMD -S .\MSSQLSERVER08 -V 17 -...
0
votes
1answer
157 views

Encrypt connection when using sqlcmd

Trying to connect database with an encrypted connection, tried below sql queries: sqlcmd -N -E -S tcp:SQLSERVER,1234 -U username -P password -d Database -Q "INSERT INTO table1 VALUES(1,2,2) ERROR:...
8
votes
3answers
46k views

How to connect to SQL Server using sqlcmd on Linux?

I have set up the Microsoft ODBC Driver 13 for SQL Server on an Ubuntu 16.04 machine. I am now trying to test a database connection, that includes both the server name and an instance name. The ...
2
votes
2answers
1k views

How to setup db credentials for `sqlcmd` using a config file?

When I'm using mysql client, I can configure my db credentials in ~/.my.ini. How can I achieve similar thing with sqlcmd on Linux? Where and what filename I should create? My goal is to avoid keep ...
0
votes
1answer
253 views

How can I increase the length of the string returned by object_definition in sqlcmd?

I have an sql script that uses select object_defintion(object_id(...)) to extract the definition from a view. This script is run with sqlcmd: sqlcmd -i extract.sql -o %oudir%\extracted.dat. ...
0
votes
1answer
557 views

SQLCMD does not print Rows affected in log file

I am calling stored procedure using SQLCMD which will insert data into multiple tables. And output of that procedure is captured in log file using -o. But, i can't see Row(s) affected any where in the ...
2
votes
1answer
66 views

SQLCMD external editor

I have set the environment variable SQLCMDEDITOR=gvim to invoke an vim with the ED command of SQLCMD. From my old Windows 7 computer, it used to work. I have now a new laptop (windows 10) and, when ...
2
votes
1answer
2k views

sqlcmd returning literal 'NULL' for null columns when outputting to CSV

I'm using sqlcmd (SQL Server 2008 R2) to execute a simple query to output data to a .csv file. In the SQL file, I have the following code: USE [OSCAR_UK] SELECT DISTINCT ISNULL(LTRIM(RTRIM(il.[...
1
vote
2answers
2k views

How to print results in SQLcmd window

I'tm trying to show in SQLcmd window the results of these queries: SELECT SYSDATETIME() AS "date"; PRINT 'EXTRAÍDO POR:' SELECT SUSER_NAME() AS "Owner" PRINT 'PASSWORD SETTINGS'; exec ...
0
votes
1answer
38 views

Why do I need DAC if I am able to connect to the server via sqlcmd?

DAC attracted my attention at the moment when I was unable to connect to the SQL Server using a traditional way (the reason was deleting logon trigger). I made some searches on the web and it turned ...
1
vote
2answers
59 views

How to create a csv with SQLCMD which can be imported into another database system

I may be doing this all the wrong way so please point me in the right direction if I am missing something. I have an Ubuntu server with SQLCMD installed and a Windows Server with a MSSQL database. I ...
1
vote
3answers
580 views

Invoke-SQLCmd Date output format

I’m having a problem with a result set that I am getting from a stored procedure when running a PowerShell script (Using Invoke-SQLCmd) to get the results and send the output to a .csv file. The date ...
3
votes
2answers
387 views

Suppress database change message in SQLCMD.exe

I am writing a script generation script. The script is generating list of DDL statments. The util_generator.sql generation starts with database connection: USE [TARGET_DATABASE] GO ... Many queries ...
1
vote
1answer
87 views

Session ID in SQLCMD running multi-batch script

My script contains multiple GO keywords. I know that SQLCMD interprets GO as a batch delimiter, so the code is not run as a single block but instead each part between the delimiters (a batch) is run ...
3
votes
3answers
27k views

Pass parameters to a procedure with SQLcmd

I use this SQL command: sqlcmd -v first_date="30/09/2015" last_date="15/09/2016" And I would like to pass that parameters to a stored procedure: ALTER PROCEDURE [dbo].[_testProcedure] WITH ...
1
vote
1answer
86 views

Restore ALL databases with sqlcmd in SQL Server (Express, Docker, 2017)

These documentation articles https://docs.microsoft.com/en-us/sql/linux/tutorial-restore-backup-in-sql-server-container?view=sql-server-2017 and https://docs.microsoft.com/en-us/sql/linux/sql-...
0
votes
3answers
654 views

Check if a SQL Login exists without SA

How can I check if a SQL Login exists for an arbitrary domain user if the account I'm running doesn't have SA rights to the instance (but will be dbo on at least one DB) Ideally I'd like the solution ...
1
vote
1answer
1k views

exporting a sql view to a csv file

Whilst I can just about script to pull data via queries, I'm finding it very difficult to figure out how to export the results of a query to a .csv file and save in a network storage location (novice ...
3
votes
2answers
2k views

SQLCMD: “Login failed for user” on SQL Azure, but it works with SSMS

I have an SQL Azure database, and I'm able to connect to it using SQL Server Management Studio. When connecting to it, it displays myServer.database.windows.net (SQL Server 12.0.2000.8 - myUser) ...
5
votes
1answer
1k views

How to Natively Return Output when using Invoke-Sqlcmd?

How do I natively log output from the PowerShell Invoke-Sqlcmd? I am using Invoke-Sqlcmd to loop through a large (50,000-90,000 SQL files w/ 1-10 inserts in each) set of small SQL insert statements. ...
0
votes
2answers
222 views

Are the switches for the SQLCMD command case sensitive?

I have MS SQL Server 2014 Management Studio installed on two computers, both of which run on Windows 10. The switches for SQLCMD command are case-sensitive on one computer, but it is not on the other ...
2
votes
1answer
295 views

SQLCMD :connect directive - how can I specify connection protocol?

In a script I have the directive :connect DbServer and it seems that if I run this script in SQLCMD (like this: sqlcmd -i script.sql then sqlcmd attempts to connect using Named Pipes (which doesn'...
0
votes
1answer
322 views

SQLCMD cannot connect my named instance

I am using SQL Server 2017 based on Windows server 2016. I am trying to connect my named instance, but I got the error message as below screenshot: So I tried to reinstall ODBC Driver 13. But I got ...
0
votes
1answer
682 views

Msg 102, Level 15, State 1, Server DESKTOP-U368A1B, Line 1 Incorrect syntax near '1'

I get the above error message when i run the following perl script from the cmd, that is supposed to do some transaction in my database. #!/usr/bin/perl. use warnings; use strict; my ( $pid1, $...
3
votes
1answer
673 views

How do I force windows to use a specific version of SQLCMD?

I have several versions of SSMS installed on my machine. We have legacy servers running several versions of SQL Server, mainly 2008, 2012, and 2014. I use SQLCMD all the time, but it seems to default ...
1
vote
1answer
1k views

How to format the output of SQL queries on SQLCMD for SQL Server 2017 on RHEL Linux 7.3?

I have installed SQL Server 2017 on RHEL Linux 7.3, and using SQLCMD utility for querying the SQL Server. When I try to query for example: 'SELECT * FROM SYS.DATABASES'. I get output like the ...
0
votes
2answers
372 views

How to report stats on restore via sqlcmd?

I've inherited a batch file script that calls sqlcmd with parameters. One of the parameters is the path to a SQL file. That file includes a database restore command. The command in the SQL file ...
4
votes
1answer
747 views

SSMS generated script failing to execute

So I am in a situation where I need to import a small DB (under 1GB) from a newer version of SQL Server (I am restoring to a 2014 SQL Server from a 2016 SQL server), without a direct connection ...
2
votes
2answers
491 views

How do I install SQL-Server Tools if I can't use curl?

Attempting to install mssql-tools, I get $ sudo apt-get install mssql-tools Reading package lists... Done Building dependency tree... 50% Building dependency tree Reading state information......
5
votes
1answer
3k views

What are valid connection strings for SSMS login box?

What are valid connection strings for SSMS login box? Every once in a while I will have to connect to an instance of SQL Server with some specific configuration setting or in a DMZ where no host ...
-1
votes
1answer
112 views

How to update the first row in the exported query from sqlcmd

I am trying to find an easy way of updating the first row in the export of a sqlcmd query to CT_EVENT,,,,,,,,,,,,,,,,,,,,,,,,. I found this article in stack overflow which builds the csv format. I've ...
0
votes
1answer
775 views

Permission issue on restore of the db from primary to secondary [duplicate]

while restoring the User DB from primary to secondary replica through query in cmd prompt and got following error message Msg 262, Level 14, State 1, CREATE DATABASE permission denied in database '...