sqlcmd

SQL Server: INSERT/UPDATE/DELETE failed because the following SET options have incorrect settings: ‘QUOTED_IDENTIFIER’

删除回忆录丶 提交于 2019-12-11 12:36:10
问题 I have this rather awkward problem: For two weeks now, whenever after I've updated/created stored procedures using my SQL scripts, when these stored procedures are run, they fail with above error. Other posts dealing with this problem didn't help in my case. Here's a number of parameters, helping to exclude common solutions which do not apply in my case: My stored procedure scripts work flawlessly on my laptop (SQL Server 2012, Windows Server 2008 R2). My stored procedure scripts correctly

Errorlevel in batch file not working

怎甘沉沦 提交于 2019-12-11 11:43:03
问题 I'm trying to delete the database using sqlcmd with a batch script. The problem I was facing is the code isnot entering the errorhandler block if mytest database is not available in the sql. @echo off @echo IF ELSE DEMO sqlcmd -S <servername> -U <username> -P <password> -Q "DROP DATABASE Mytest" IF ERRORLEVEL 1 goto err_handler goto done :err_handler echo handle the error here goto end :done echo script completion code here :end @echo %Message% pause and it gives the following output: IF ELSE

how to include a “:” as a parameter in powershell?

浪尽此生 提交于 2019-12-11 10:56:20
问题 i have a simple powershell script, like this sqlcmd -S. -E -Q 'select ''$(x)''' -v x="c:a" but i always got the error message Sqlcmd: ':a': Invalid argument. Enter '-?' for help. i figured out that it is the ":" in the argument caused the problem, but i do not know how to escape it. thanks, David 回答1: sorry that i have to answer to my own question again. the only way to solve this problem is to use '+' to concatenate the two string, and the ':' will be reserved. e.g. $a="abc"+":123" 回答2: You

Need to understand output of sqlcmd.exe

若如初见. 提交于 2019-12-11 07:00:05
问题 I was advised to make another question, from here - Need help to make sqlcmd run as per requirements My sqlcmd.exe is invoked with a command of the form - sqlcmd -S .\MYSQLSERVER2008 -U MyUsername -P MyPassword -i C:\Database\hugescript.sql > log.txt 2> error.txt Now, log.txt says - Canceling connection. Please wait... Error.txt says - Sqlcmd: Error: Microsoft SQL Server Native Client 10.0 : Operation was canceled.. How do I find out the cause of the problem and fix it ? 来源: https:/

Powershell - SQL query result to variable with properties

隐身守侯 提交于 2019-12-11 04:23:57
问题 Why the stored output of SQLCMD has only Length property instead of column names ?. Is it not possible to store sqlcmd output with its properties? Invoke-sqlcmd stores it correctly but Invoke-SQLcmd takes a bit longer to process so I'm trying to make it work with SQLcmd as this method will be part of different scripts that are scheduled to run every minute, once ever hour etc., Any idea if this is possible or what the issue is? Store output and echo $var: PS C:> $var=(SQLCMD -S 'x.x.x.x' -U

Issue executing an exe when the path has spaces.

牧云@^-^@ 提交于 2019-12-11 03:13:00
问题 This works: SET server=MyServer SET db=MyDb FOR /F "usebackq tokens=1" %%i IN (`sqlcmd -S %server% -d %db% -w200 -h-1 -E -Q "set nocount on; select REPORTING_DATE FROM dbo.CURRENT_REPORTING_DATE"`) DO set REPORTING_DATE=%%i ECHO The Reporting Date is %REPORTING_DATE% But when I try to fully qualify the path to sqlcmd... SET sqlcmdexe="C:\Program Files\Microsoft SQL Server\100\Tools\Binn\sqlcmd.exe" SET server=MyServer SET db=MyDb FOR /F "usebackq tokens=1" %%i IN (` %sqlcmdexe% -S %server% -d

Process file with for command in alphabetical order

二次信任 提交于 2019-12-11 02:52:01
问题 I must run n query SQL for update more database. I created a batch file to help me in this activity but the queries are not executed ordered by name. I use this batch command: for %%I in (.\*.sql) DO sqlcmd -S .\istance -U username -P password -d dbname -i %%I -o .\%%I.log How can I run all queries ordered by name? Thanks for your answer. Note: I use Windows 7. 回答1: Only reason for the FOR command not enumerating files in name order is that the file system is not NTFS. FAT filesystem

SQL Server 2008 - use cmd to output with headers to .csv

回眸只為那壹抹淺笑 提交于 2019-12-11 00:01:52
问题 I have a pretty simple question (and these are typically the ones I spend most of my time tearing my hair out about). I am using a batch file to execute all the .sql queries that are in the same directory as the batch, and to save all their results to various .csv file. Here is my code: @echo off REM Check that all parameters are present @IF "%1"=="" goto error @IF "%2"=="" goto error @IF "%3"=="" goto error @IF "%4"=="" goto error REM For every *.sql file in this folder "." and all its

Escape variable in sqlcmd / Invoke-SqlCmd

戏子无情 提交于 2019-12-10 17:34:03
问题 I am using powershell and using Invoke-SqlCmd. I am able to pass variables to SQL: $variables = @( "MyVariable='hello'" ) Invoke-SqlCmd ` -ServerInstance 'localhost' ` -Database 'master' ` -Username 'matthew' ` -Password 'qwerty' ` -Query 'SELECT $(MyVariable) AS foo' ` -Variable $variables This gives me back hello as expected. However, if I have a variable with a value containing an equals ( = ): $variables = @("MyVariable='aGVsbG8NCg=='") # base64 encoded 'hello' It gives me the following

SQLCMD scripting error

廉价感情. 提交于 2019-12-10 17:15:10
问题 i am using SQLCMD to run a .sql file which is 270 MB. The script file (.sql) was generated using Red Gate SQL Data Compare synchronization wizard. I cannot run it from SSMS because of insufficient memory. I log into the server and go to command prompt and it opens up command prompt C:\Users\USER1> then i type in > C:\Users\USER1>SQLCMD -U sa -P PWD -d DATA_FEAT -i F:\SYNC\DATA-DATA_FEAT-20140709.sql -o F:\SYNC\DATA-DATA_FEAT-20140709result.txt but i get Sqlcmd: Error: Scripting error. i am