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
60 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 ...
0
votes
2answers
53 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 ...
0
votes
0answers
32 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 ...
0
votes
0answers
51 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?
0
votes
1answer
80 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:...
1
vote
2answers
106 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: :...
0
votes
1answer
116 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 ...
2
votes
1answer
53 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 ...
1
vote
2answers
863 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
36 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
1answer
307 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 ...
1
vote
2answers
47 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
356 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
266 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
72 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 ...
1
vote
1answer
80 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
451 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 ...
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
182 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
261 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
270 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
614 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
546 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 ...
4
votes
1answer
613 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 ...
0
votes
2answers
328 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 ...
2
votes
2answers
436 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......
2
votes
2answers
218 views

Sqlcmd: 'KReadOnly': Unknown Option

I am using SQL Server 2014 SP2 with AG, running this command: sqlcmd -S ABC-ISELL -E -d ABP_SFA_BMB -K ReadOnly Where ABC-ISELL is the listener name, I am getting this error: Sqlcmd: 'KReadOnly': ...
1
vote
4answers
2k 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 ...
5
votes
3answers
2k views

sqlcmd :out not working as expected?

Consider the following code: DECLARE @db sysname; DECLARE @filename varchar(260); DECLARE cur CURSOR LOCAL FORWARD_ONLY STATIC READ_ONLY FOR SELECT d.name FROM sys.databases d; OPEN cur; FETCH NEXT ...
-1
votes
1answer
104 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 ...
5
votes
2answers
1k views

SQL Server 2016 SQL Agent Token Not Working

I have this in scores of SQL Agent Job steps throughout my enterprise and it works as expected: sqlcmd -E -S $(ESCAPE_SQUOTE(SRVR)) -d master -Q "EXECUTE MyStoredProc etc..." But on my new SQL ...
0
votes
1answer
2k views

How To Import Binary Dump File To SQL Server

I am trying to import a dump file which is in binary format to SQL Server using sqlcmd command. After running the import command, I am getting this error, Msg 2812, Level 16, State 62 I'm suspecting ...
1
vote
0answers
595 views

Unable to access an SQL Server 2016 named instance locally via sqlcmd when only using @@SERVERNAME value

I have a server with two instances of SQL Server 2016 SP1 CU7 running, one is the default instance (on a custom port, 9433) and the second is a named instance (on another custom port, 9434). I've ...
0
votes
1answer
282 views

sqlcmd gives no sign of failure yet doesn't work

I am running sqlcmd from a linux bash script. My target server is an Azure SQL. I execute an sql file with a lot of sql statements (around 2500). These are Insert/update/delete statements. I used the ...
0
votes
1answer
308 views

Import database from MSSQL export dump on Ubuntu localhost

I have an export file from an online database server that I need to use to generate the database locally on my system. I'm running MSSQL 2017 on Ubuntu 16.04. The export file has Program(application/...
0
votes
1answer
576 views

SQLCMD to connect to Linked server

I'm getting a login error with the below sqlcmd to connect to a linked server: SQLCMD -E -dlinkedserver -ig:\temp\script.sql -o g:\temp\test.txt My linked server which is an oracle connects through ...
8
votes
5answers
13k views

How to display MS SQL results vertically?

Here is what I've got currently when executing queries in sqlcmd: 1> SELECT 1,2,3,4 2> GO ----------- ----------- ----------- ----------- 1 2 3 4 (1 ...
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
225 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. ...
3
votes
2answers
362 views

SQL Server Temporary Table Security

I am part of a project to convert an old AS400 system to SQL server. The server is used for our payroll processing. Part of the payroll process is to break out the percentage of the biweekly wages ...
0
votes
1answer
158 views

DAC Connection using the SSMS for executing the code

Can anyone help me on below . I am trying to execute the SQLCMD with DAC (-A switch) but unable to do so . How can I do it both ways below : Execute in SSMS Query Pane Execute using PowerShell ...
2
votes
3answers
795 views

Why does sqlcmd truncate varbinary(max)?

Inside of the sys.assembly_files catalog, I can see a field named content 1> SELECT assembly_id, LEFT(name, 50), file_id, content FROM sys.assembly_files; 2> GO assembly_id ...
1
vote
1answer
2k views

difficulties working with powershell Invoke-SQLCmd

I've setup a simple sqlcmd script. Contents below. use $(dbname); select * from $(tablename) I'm then running the following Invoke SQLCMD $SQLCMDVarArr = "dbname='MyDatabase'", "Tablename='...
-4
votes
1answer
192 views

Does sqlcmd.exe have “spyware”?

I'm just wondering if the sqlcmd.exe has client-side Telemetry, CEIP (Customer Experience Improvement Program), or any other form of "spyware" baked into it and turned on by default? And if so how to ...
3
votes
1answer
601 views

How do I log into the Dedicated Admin Console (DAC) on Linux?

sqlcmd is documented to have, Login-Related Options -A Logs in to SQL Server with a Dedicated Administrator Connection (DAC). This kind of connection is used to troubleshoot a server. This ...
5
votes
1answer
541 views

sqlcmd history?

How can I list/review the sqlcmd history? Mysql, Postgresql and sqlite write out to dot files: .mysql_history, .psql_history and .sqlite_history. I'm looking for an equivalent (or approximation) ...
1
vote
1answer
556 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 ...
2
votes
1answer
369 views

Decrypting a Master Key works well using SQLCMD but not in the script

I would like to use a script to automatize the process of migration of a Db in another instance. The DB is encrypted, so after restore it I need to decrypt it and encrypt again using the new Service ...