The error message when running my scripts includes:
Script block number: 9512; Block line 25;
What is a Script block number and how do I go to it in Visual Studio? (I'm using dbUp to create my database.
Thinking about Clay's comments, I went out to the source code for dbUp, which is over at the Git website. It turns out that the block line is the same as the sqlException.LineNumber. SqlException.LineNumber Property, according to MSDN, "Gets the line number within the Transact-SQL command batch or stored procedure that generated the error." So, now I have my answer!
Related
I have a program flow where a database command button writes a file with data from the current record, then executes a batch file (windows) to knit a markdown file using the output from the database as inputs.
"C:\Program Files\R\R-4.1.1\bin\i386\Rscript.exe" -e "library('knitr'); rmarkdown::render('MyMarkdownFile.Rmd', output_file='MyOutput.html')"
The final step is that this file is opened in a browser.
start "" "MyOutput.html"
I do not use a unique file name, the same html file (MyOutput.html in the example above) is over-written each time. Sometimes the markdown process throws an error and halts execution during the knit. In these cases the previous version of the html file is then opened by the next batch command and, to the users, this may be confusing: they may assume they are seeing the current report when in fact they are not. (Note there are clear labels to distinguish, but still ...). I am wondering if there is a way to somehow "know" within the batch file that there has been an error in the knit process and thereby halt execution of the batch so that the html is not opened in the final step.
See Mofi's comment. This is the answer. Simply inserting && between batch commands halts execution when the knit returns an error. Thank you.
I am using SAS Studio (the browser version) instead of a desktop SAS program.
I am trying to read a .sas7bdat file that I have uploaded onto a folder on SAS Studio.
libname HW5 '~/home/xxxxxxxxxxxx/sasuser.v94/HW5';
DATA FILE1;
set HW5.orders;
RUN;
I get the error:
ERROR: File HW5.ORDERS.DATA does not exist.
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.FILE1 may be incomplete. When this step was stopped there
were 0 observations and 0 variables.
WARNING: Data set WORK.DISCOUNT_RET was not replaced because this step was stopped.
Here is the image of the folder:
https://ibb.co/hN83ua
I realize this is a simple error but I don't know how to fix it. Thanks! If nothing works, can i read this via infile?
Right click on the HW5 folder in the list on the left and select properties. This should show you the physical location for that folder. Copy it and paste it into your LIBNAME statement enclosed in quotes. Most likely the issue was your inclusion of the ~ in front of the path.
libname HW5 '/home/xxxxxxxxxxxx/sasuser.v94/HW5';
If I execute the following script:
EXECUTE LongRunningSP1
GO
EXECUTE LongRunningSP2
GO
Assuming both procedures take several minutes, will the GO batching cause any concurrency to happen or is LongRunningSP1 guaranteed to finish before LongRunningSP2 starts?
The GO will just split your code in batches, but it won't cause any concurrency: all batches are executed one at time, in the order they appear in the code.
LongRunningSP1 is guaranteed to finish before LongRunningSP2 with or without the GO in between; GO is a batch separator for the command processor.
It's easier to see what it does when using the command line utility SQLCMD.
SQLCMD
1> exec LongRunningSP1
-- nothing happens
2> exec LongRunningSP2
-- nothing happens
3> GO
-- both procs are run, first SP1, then SP2
Yes!! Go will actually make it into batches to be executed.
So it's LongRunningSP1 which gets completed first, ALWAYS!
GO is not a Transact-SQL statement; it is a command recognized by the sqlcmd and osql utilities and SQL Server Management Studio Code editor. It is a batch terminator, it will not change the order of your query. You can however change it to whatever you want under options.
Here are a set of very simple, easy steps to customize the batch separator in SSMS:
Launch SSMS
Go to Tools –> Options
Click on the “Query Execution” node
Notice that we have an option to change the Batch Separator
Change the batch separator
Click “OK”
So we use osql to run in stored procedures as part of our build process. We use a project with an sp folder that gets published with applications as part of a build pack.
I used Visual Studio to create this project structure and created the sql scripts to run in the procs.
Visual Studio saved the files with UTF8 formatting (by default). osql when running in the scripts complained about every single script having a syntax error on line 1 i.e.
> Incorrect syntax near '´'. 1> 2> Msg 102, Level 15, State 1,
> Server GBEPIAP-SQL01, Line 1
Rather baffling.
Anyway; to fix the issue, the sql scripts could be saved with Unicode Codepage 1200 (File -> Advanced Save Options)
et voila - problem gone
Now that's left me with an even bigger problem; I have over 200 proc scripts that I need to open, change encoding and save with the new encoding.
Can any powershell guru do me up a quick script to change the encoding of every file in a folder to Unicode Codepage 1200? Would be doing me a favour while also saving time.
In the end I used the approach documented here
Save all files in Visual Studio project as UTF-8
But instead of UTF8; I specified Unicode.
foreach (var f in new DirectoryInfo(#"...").GetFiles("*.sql", SearchOption.AllDirectories)) {
string s = File.ReadAllText(f.FullName);
File.WriteAllText (f.FullName, s, Encoding.Unicode);
}
I have a stored procedure in Sybase that uses reorg rebuild statement in a loop for all the tables in my database. What I want to do is to suppress the reorg rebuild sysmessages for tables that succedeed the procedure and only to print the tables that were locked etc...thus the problematic ones....The thing is that I did not succeed to find out anything to use in manual or in any workshops...dow you have any idea?
Thanks in advance !!!!!
If you are running the SQL with isql at a command prompt, you can always capture the output in a text file and filter it out with other tools.
Create a script to run the SQL in isql and then use a script that calls a text processing tool (awk,sed,...) to only find the lines of interest.
Here is an example from a windows batch file with a regex that removes lines that start with a space (i.e. Rows Effected messages)
isql -SDBDEV1 -DMyDbName -U%DBLOG% -P%DBPWD% -iLoadBatchStats.sql -o%TEMP%\LoadBatchStats.log
type %TEMP%\LoadBatchStats.log | gawk "/^[ ]/{print $0}" >>%TEMP%\LoadBatchSummary.log