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
0
votes
1answer
31 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 ...
1
vote
1answer
38 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
126 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
33 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 ...
0
votes
1answer
78 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
33 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
96 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
153 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
50 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
61 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
194 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
483 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
516 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
125 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
192 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
179 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
511 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
348 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
689 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
0answers
387 views

Easiest way to update XML inside of a SQL table column?

I have an SQL DB, Directory. It contains a table, dbo.User. Within that table there is a column, Info. The Info column contains ~1000 lines of xml tags. Well I want to modify only one of those tags, ...
4
votes
1answer
387 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
250 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
368 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
186 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
3answers
2k views

help in connecting the sql server 2017 developer edition

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
93 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
1k 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
532 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
230 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
288 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
464 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
11k 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 ...
1
vote
1answer
953 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
186 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
315 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
142 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
640 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
184 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
567 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 ...
4
votes
1answer
484 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
510 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
329 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 ...
4
votes
0answers
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 ...
0
votes
1answer
616 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 '...
1
vote
0answers
2k views

sqlcmd access denied on c:/

I tried to execute a simple .sql script from the command prompt and this is the output I got C:\Users\Administrator>sqlcmd -S {machine name}\SQLEXPRESS -i C:/SqlScripts/UpdateStat.sql Sqlcmd: ...
1
vote
1answer
93 views

Script not working after adding try and catch

I have a working script that I modified to work with SQLCMD since I need to invoke this script remotely. Here is my script: :ON ERROR EXIT USE [master] GO BEGIN TRY /****** Declare Database name **...
2
votes
1answer
249 views

Messages in SQLCMD script output are not in order

I am running a batch file that launches a SQLCMD script that creates an Agent job from TFS Release Manager. The script assigns SQLCMD parameters to variables, lists the variables using selects and ...