sqlcmd

Return value of SQLCMD

*爱你&永不变心* 提交于 2019-12-30 05:59:49
问题 I need to check the exit status (success/failure) of a query run through SQLCMD utility. For example, the server I am connecting doesn't have a database name EastWind . Then, the command below fails with the message ... > "C:\Program Files\Microsoft SQL Server\100\Tools\Binn\SQLCMD.EXE" -S ZEPHIR -E -Q "USE WestWind" Changed database context to 'WestWind'. > echo %errorlevel% 0 > "C:\Program Files\Microsoft SQL Server\100\Tools\Binn\SQLCMD.EXE" -S ZEPHIR -E -Q "USE EastWind" Database

SQLCMD using batch variable in query

人走茶凉 提交于 2019-12-25 07:03:44
问题 If I'm using sqlcmd in a batch script, can I reference a batch variable inside the query? So that if I do something like for /f "delims= " %%a in ('sqlcmd -S SERVER -d DATABASE -Q "SELECT Column1 FROM Table1 WHERE Column1=[specific number]"') do set var1=%%a how could I do something like this?: for /f "delims= " %%b in ('sqlcmd -S SERVER -d DATABASE -Q "SELECT Column2 FROM Table1 WHERE Column2=[var1]"' do set var2=%%b So that the WHERE condition in the second sqlcmd statement is using the

SQLCMD using batch variable in query

大憨熊 提交于 2019-12-25 07:03:30
问题 If I'm using sqlcmd in a batch script, can I reference a batch variable inside the query? So that if I do something like for /f "delims= " %%a in ('sqlcmd -S SERVER -d DATABASE -Q "SELECT Column1 FROM Table1 WHERE Column1=[specific number]"') do set var1=%%a how could I do something like this?: for /f "delims= " %%b in ('sqlcmd -S SERVER -d DATABASE -Q "SELECT Column2 FROM Table1 WHERE Column2=[var1]"' do set var2=%%b So that the WHERE condition in the second sqlcmd statement is using the

sqlcmd runs into error while parsing my .sql file

僤鯓⒐⒋嵵緔 提交于 2019-12-25 05:29:12
问题 I am invoking sqlcmd as follows: sqlcmd -S SERVERNAME\SQLEXPRESS -i "C:\Documents and Settings\user\Desktop\data\bigDB.sql" And I get an error while the script is executing: Sqlcmd: Error: Syntax error at line 86626 near command '%' in file 'C:\Documents and Settings\user\Desktop\data\bigDB.sql'. How do I tell sqlcmd to ignore the current record and keep running? I think i could edit bigDB.sql and include an :On Error Ignore directive at the top - but the bigDB.sql file is 5GB is size - i

Trouble connecting to localdb via SQLCMD in PowerShell - what is server instance name?

百般思念 提交于 2019-12-25 03:34:52
问题 SQL Server newbie here - I'm trying to access the localdb\MSSQLLocalDB server on my computer through PowerShell with the SQLCMD utility. I'm using PowerShell v5, .NET v5.0, and The server name is (localdb)\MSSQLLocalDB when I connect to it in Microsoft SQL Server Management Studio 2014. PS C:\> sqlcmd -S localdb\MSSQLLocalDB and PS C:\> sqlcmd -S .\localdb\MSSQLLocalDB result in this error: Sqlcmd: Error: Microsoft ODBC Driver 11 for SQL Server : SQL Server Network Interfaces: Error Locating

Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON' in SQL Server 2008

ぃ、小莉子 提交于 2019-12-25 03:04:51
问题 I am executing a script by using file like below: EXEC master.dbo.xp_cmdshell 'sqlcmd -d TE07 -S ServerName -i D:\TE07.sql' When executing the above line I am getting the below error: Msg 18456, Level 14, State 1, Server WIN-T7NMRSDEBNP, Line 1 Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON'. I have read a lot but I am not clear about this. In many articles it is define as a LinkedServer issue. Can anyone please suggest me. 回答1: We have to use username and password also while executing

Capturing in PowerShell different sqlcmd exitcode for connectivity/data issues

社会主义新天地 提交于 2019-12-24 06:49:31
问题 I am calling sqlcmd from PowerShell to execute a T-SQL script. Currently I am using ":On Error exit" to exit the script if there is an error caused by the data used violating a constraint etc. This is handled by PowerShell detecting the $SqlcmdProcess.ExitCode of 1. However, if there is a connectivity issue with the database, sqlcmd also gives an ExitCode of 1. Is there a way to set the :On Error ExitCode to something other than 1? I'm aware of using something like :Exit(SELECT 2) to do this,

Capturing in PowerShell different sqlcmd exitcode for connectivity/data issues

情到浓时终转凉″ 提交于 2019-12-24 06:49:29
问题 I am calling sqlcmd from PowerShell to execute a T-SQL script. Currently I am using ":On Error exit" to exit the script if there is an error caused by the data used violating a constraint etc. This is handled by PowerShell detecting the $SqlcmdProcess.ExitCode of 1. However, if there is a connectivity issue with the database, sqlcmd also gives an ExitCode of 1. Is there a way to set the :On Error ExitCode to something other than 1? I'm aware of using something like :Exit(SELECT 2) to do this,

How to export more than 1MB in XML format using sqlcmd and without an input file?

两盒软妹~` 提交于 2019-12-24 06:18:16
问题 In SQL Server 2008, I want to export the result of a stored procedure to a file using sqlcmd utility. Now the end of my stored procedure is a select statement with a "for xml path.." clause at the end. I read on BOL that if I don't want my output truncated when reaching 1MB file size, I have to use this :XML ON command, but it should be placed on its own line, before calling the stored procedure. Does any of you experts know if it is possible to do that without specifying an input file for

Regex lookahead/lookbehind match for SQL script

有些话、适合烂在心里 提交于 2019-12-24 00:38:49
问题 I'm trying to analyse some SQLCMD scripts for code quality tests. I have a regex not working as expected: ^(\s*)USE (\[?)(?<![master|\$])(.)+(\]?) I'm trying to match: Strings that start with USE (ignore whitespace) Followed by optional square bracket Followed by 1 or more non-whitespace characters. EXCEPT where that text is "master" (case insensitive) OR EXCEPT where that that text is a $ symbol Expected results: USE [master] - don't match USE [$(CompiledDatabaseName)] - don't match USE