SQL72007: The syntax check failed 'Unexpected end of file occurred.' in batch near : - visual-studio-2017

In SSDT project (using VS2017/VS2015, SSDT version 15.1.61702.140), I cannot get my project to build. The compiler keeps complaining about the sql statement in my PostDeploymentScript (yes, I have set the BuildAction property to PostDeploy). The sql statement is:
if ('$(env)' = 'dvp')
BEGIN
PRINT 'creating users for dvp'
:r .\SecurityAdditions\usersdvp.sql
END
ELSE IF ('$(env)' = 'qat')
BEGIN
PRINT 'creating users for qat'
:r .\SecurityAdditions\usersqat.sql
END
The actual error message is:
D:\My\File\Path\PostDeploymentScript.sql (lineNum, col): Error: SQL72007:
The syntax check failed 'Unexpected end of file occurred.' in the batch near:
The line num referred in the error message in the last line (end). Any idea what's causing this?

Apparently the problem was due to the GO statements I had in the files I was referencing. Having GO statements inside if else block is invalid. Here is an article explaining that. I was able to get it work by removing all GO statements from the referenced files and by splitting if else to two if.
IF ('$(env)' = 'dvp')
BEGIN
:R .\SecurityAdditions\UsersDVP.sql
END
IF ('$(env)' = 'qat')
BEGIN
:R .\SecurityAdditions\UsersQAT.sql
END
GO

I had this same error because I forgot to end one of the scripts being included in the post deployment script with a GO statement. What makes it hard fix is that the error will point to the first line in the next script instead of the script where the GO statement is missing.

I ran into this issue while I was trying to create database users in a SQL Database project. Setting the build action to None is no use because then your script doesn't run during the deployment.
I was using a script like this to create the users:
IF NOT EXISTS (SELECT * FROM sys.sysusers WHERE name='$(DbUserName)')
BEGIN
CREATE USER [$(DbUserName)] WITH PASSWORD = '$(DbPassword)';
ALTER ROLE [db_owner] ADD MEMBER [$(DbUserName)];
END
I had two SQLCMD variables in the project file and setting a default value for one of them actually resolved the issue. It's really weird but I hope this helps some poor soul one day :)

I would like to share my experience here.
I got same error building my sql project but scenario was different and tricky.
I introduced new column in one of my database table and I needed to populate that column for already existing rows in that table. So basically it should be one time process and hence I decided to create post deployment script to do that. This post deployment script
began with IF condition to make sure it run only once for a given database. Please note this does not allow GO statement.
then Create Function to create temporary function. This needs GO statement before Create Function mainly because it makes changes in database schema. This was tricky because IF does not allow GO statement.
then Update query using temp function to achieve my requirement. This is fine without GO statement
then DROP FUNCTION to remove temporary function. This is also database schema change and ideally needs GO statement.
To handle this situation without any GO statement
I created a variable let's say '#CreateFuntion NAVARCHAR(MAX)' and set it with whole Create Function statement.
Executed Create Function using "EXEC sp_executesql #CreateFunction". This runs Create Function in separate batch. I was expecting Drop Function will need same treatment but in my case it worked without GO and "EXEC sp_executesql" may be because it was last statement in the script and would anyway run in next batch.
Everything else as it is

Another reason this could happen is if a post deployment script has a BEGIN statement without a corresponding END line. In such a case, any subsequent GO in anther future script will cause this error. I stumbled across this due to my own absent-mindedness when editing one of the post-deployment scripts.

Related

Oracle APEX - how to raise an error in your own custom validation process without showing it on the error page

I am using Oracle Apex 19.2. I need to create a Form Page with many fields and many validations.
Instead of creating one Validation Routine for every field and check I want to put them all into one PL/SQL procedure and create Process Routine in APEX. Inside that pl/sql procedure I would perform all necessary checks and use apex_error.add_errorto add all errors into stack.
If there is at least one error I want to break procedure execution and show it on the page. The problem is that the procedure completes always successfully so no error is displayed. I tried raise_application_error but my custom error is also visible on error page.
The same applies when rising apex_application.e_stop_apex_engine - apart from my custom validations there is also ORA-20876 error from apex_application.stop_apex_engine.
Is there any way I could either break procedure execution without raising an error or ignore somehow the error I raise to break it?
Problem solved.
I defined my PL/SQL procedure as an APEX Process routine. Instead of that, I should have done it as an APEX Validation. It looks like APEX carries out all validations and then, even if they all went ok, it checks error stack and does not proceed with processing if there is any error. Below steps how to achieve it.
Define a new APEX Validation with Validation Type = PL/SQL Function Body (returning Boolean)
Here starts the tricky part - in the PL/SQL code field you put your PL/SQL procedure and you always return true. It looks like:
your_plsql_package.your_procedure;
return true;
In the mandatory field Error Message you write whatever message you want - It will never be displayed on the error page.
And that is it. Instead of having dozens validations on the page you can have one procedure to rule them all :) However, it could be more developer friendly.

Trouble Adding Publishing Action to append to an existing big query table?

I have a dataflow flow that appends to an existing bigquery table which has been working for the last few weeks. When i run it now it gives me the error "Cannot run job. Please reload the page and try again." and won't even start the job.
After trying a lot of things, i made a copy of the flow and when the publishing action is creating a new csv file, it works but when i try to
Add a publishing action to an existing big query table,it keeps giving me another bizarre error "SyntaxError: Unexpected token C in JSON at position 0".
I have no idea what is happening since everything used to work perfectly and i made no changes whatsoever.
I am not adding anything new, but I want to give you an answer.
It seems that one of your JSON inputs may be malformed. Try logging it to see what's the problem - and also try skipping malformed JSON strings.
As mentioned in past comments, I suggest to check your logs in StackDriver to find out why are you getting the:
"Cannot run job. Please reload the page and try again."
Also if you can retrieve more information about the error from those logs, It'd be useful to assist you further.
Besides the above, maybe we can solve this issue easier by only just checking the json format, here I put an easy third party json validator and here you can check where you have the error in your json.

Couldn't able to find buit-in function $PMTargetName#numAffectedRows

Hi Iam novice to Informatica, I tried to get the count of inserted rows to target to WF variable, So that I can write a condition to a link to proceed to next session.
I went through few web guides and found $PMTargetName#numAppliedRows.
But I didn't able to find this property under Built-in properties in Post session on success variable assignment.
Even I tried to assign a variable in mapping level with this property, but I am getting error like Invalid symbol reference.
$PMTargetName#numAppliedRows is NOT listed anywhere among any variables. Neither in built-in nor anywhere else. Still - you can use it. Just remember to replace the TargetName with the name of your target transformation, e.g.: if you insert data to AccountList table, you'd need to use the condition $PMAccountList#numAppliedRows. Hope this helps.
Please use this link workflow variable :-
Name: TgtSuccessRows
Desciption: Rows successfully loaded
Datatype: integer
But issue is you can not track data loaded for multiple targets.

Powershell Get-WebVirtualDirectory : Specified cast is not valid

I've narrowed my code down to this-
Function Check-VirtualPhysicalPath{
Param([Parameter(Mandatory=$True)] [AllowEmptyString()][String]$Page)
#This creates an arraylist of items that are our virtual/physical paths
$WebVD= Get-WebVirtualDirectory
}
when I run this script in a function setting the results of 'Get-WebVirtualDirectory' returns a casting error. This has me baffled because when i try to run the line
$WebVD= Get-WebVirtualDirectory
in either a script or merely on the console there are no errors returned and i can access the variable and the data is correct. What am I doing wrong?
Now as a side-note this is merely the problematic code so i'm not including everything, but even when i comment everything else out i end up just running what you see here with problems just the same.
i'm calling the code with this in a separate script
$page = [string]$(gc "C:\page.txt")
. C:\VP.ps1
$(Check-VirtualPhysicalPath($page))
Powershell is reacting like i'm casting the $WebVD variable, I'm not sure if this is a bug or if i'm missing something entirely...
Edit:
it looks like i forgot to pull out that part of the code. I'm code crawling, the point of the hashtable is that i'm storing the number of times a resource is used in a hash table with the key being the file name and the value how many times it has been used so i use regular expressions to determine that. My question is unrelated to my other code because it's having problems even when my code only contains what you see above.

cfquery stuck and does not finish running

I've been trying to run a dynamic query inside a cfquery tag. Previously it was running fine.
So now, I can see the debugger enter the cfquery tag, but it does not finish running. It didn't seem to have made an affect to the database, since nothing was added for that insert query. Putting try & catch blocks didn't catch anything.
When I looked at the Server Monitor, under Statistics ->Database -> Active Queries -> and sure enough it is listed as an active query.
My other cfqueries tags are running fine though.
There is no problem on the database side.
I've tried changing the content of the tag to run a non dynamic insert query, but it results in the same thing. When I've changed the content of the query to a badly formed sql, it does catch the error.
Would you suspect this to be a ColdFusion problem?
Post your query. There is going to be something horribly wrong with it. My gut instinct says deadlock or cross join.