SSDT Error on build: Expected XML but encountered JSON instead - tsql

I'm using the very latest version of Visual Studio Professional 2017 (v15.9.9) with the latest SQL Server Data Tools (v15.1.61903.01040)
I create a new stored procedure in my database project, for example, with the following code:
create proc [dbo].[MyProc] as
select 'Test' as [TestColumn] FOR JSON AUTO
It won't compile with the errors below, and the keyword JSON is highlighted:
SQL46005: Expected XML but encountered JSON instead
SQL80001: Incorrect syntax near 'JSON'
It seems strange that this doesn't compile, when it's perfectly valid SQL (or am I mistaken? Is there something I'm missing? Or is it genuinely not supported?)
This issue seemed to exist for older versions of SSDT before 2016, but was reported as resolved back then, is this perhaps a recent regression? I can't find any other instances of this error or anything like it.

If you have the "Target Platform" on the .sqlproj properties set to SQL 2014 or less or "Microsoft Azure SQL Database" then this will happen, the compatibility level doesn't affect it (or at least setting my project to 2014 compatibility didn't).
This works for me with SQL 2016+ and Azure v12 with SSDT "15.1.61902.21100"
Hope it helps!
ed

Related

In a MS SSAS Project creating a Data Source ADO.NET (Postgresql) visual studio 2019 gives error 42610: syntax error at or near '['

There is an answered question concerning this topic more than
three years ago ( In a MS SSAS Project, creating a Data Source View over Npgsql (PostgreSQL) Data Source produces 42601: syntax error at or near '[' ) and (In a MS SSAS Project creating a Data Source View over npgsql (Postgresql) visual studio 2019 gives error 42610: syntax error at or near '[')
I'm facing the same issue today in ADO.NET running visual studio 2019 community on windows 10. When I create the Data Origin connection everything seems fine. However, when I try to create the Data Source View, I can choose the tables from the database but no matter what I say about the relationship between them I always get the error:" 42601 syntax error at or near '[' ". My problem is the way I use this tool, I do not write any code that can be modified. It's done by the system itself. The Data Source View is created by the wizard and as far as I know, there is no way to do it manually. Any idea about how can I overcome this error?
Please please if anyone can help me to solve this problem I really need help

In a MS SSAS Project creating a Data Source View over npgsql (Postgresql) visual studio 2019 gives error 42610: syntax error at or near '['

there is an answered question concerning this topic more than a year ago ( In a MS SSAS Project, creating a Data Source View over Npgsql (PostgreSQL) Data Source produces 42601: syntax error at or near '[' )
I'm facing the same issue today running visual studio 2019 community on windows 10. When I create the Data Origin connection everything seems fine. However, when I try to create the Data Source View, I can choose the tables from the database but no matter what I say about the relationship between them I always get the error:" 42601 syntax error at or near '[' ".
My problem is the way I use this tool, I do not write any code that can be modified. It's done by the system itself. The Data Source View is created by the wizard and as far as I know, there is no way to do it manually. Any idea about how can I overcome this error?

Reverse Engineering Code First With MySQL

Can someone help me with this problem??. I want use "Reverse Engineering Code First" with entity framework used MySQL. I was installed odbc, connector .net etc but still I cant see this... I did everything in this topic (and I have this same problem): Can't use a MySQL connection for entity framework 6
but still doesnt work :(. I was record all steps what I do it.. (Sry for english): https://youtu.be/xqEgCsu7_eU
I've gotten it to work with MySql Connector 6.9.11. Its so darned difficult and fragile I'm not sure if it was ultimately a good idea. There are at least 10 things that can go wrong and suck up hours of time. Once you get it working be very careful to not change anything. Anyhow. Here's some of my notes:
WARNING use with MySQL server 5.6.39 or 5.7.19. Do NOT use MySQL server version 5.7.21 (it fails with reverse eng) Aurora seems ok.
Install "mysql-connector-net-6.9.11.msi". There seems to be a problem with newer MySQL Connector 6.10 ?? use older 6.9.11. MUST INSTALL VIA msi file. Having the local file is not enough.
Install "mysql-for-visualstudio-1.2.8.msi" or "mysql-for-visualstudio-1.2.7.msi" ? NOTE: 1.2.7 will never uninstall correctly. VS 2015 seems to require "MySQL for Visual Studio" for EF Poco to work, (Pro,Enterprise are different)
Must have "Entity Framework Power tools Beta 4" installed as a plugin to Visual Studio 2013. Its takes some effort to get it to install for 2015, 17 but it can be done.
https://visualstudiogallery.msdn.microsoft.com/72a60b14-1581-4b9b-89f2-846072eff19d
Things that can go wrong:
ISSUE 1:
you get error "One or more errors occurred while processing template 'Entity.tt'."
This ALWAYS happens the first time i use reverse engineer after restarting VS.
Simply changing the .NET assemmbly version seems to do the trick. Target .NET 4.5 (not 4.5.1) for reverse engineer.
use .net4.5 for EF. If you see exception "System.ArgumentException: Empty path name is not legal."
remember to change back to 4.5.2 or greater.
VS2015 Edit and Continue is supported for 64-bit projects that target the .NET Framework 4.5.1. (or 4.5.2)
ISSUE 2:
System.ArgumentException: The specified store provider 'MySql.Data.MySqlClient' cannot be found in the configuration, or 'MySql.Data.MySqlClient' is not valid.
This appears to be an app/web.config issue.
??? MySql.Data.MySqlClient has more than 1 entry in in app.config ?? or bindingRedirect is wrong ?? might be wrong version consistently 6.9.11 ? MySql.Data.MySqlClient
?? Install correct version 6.9.11 in GAC not just nuget ? mysql-connector-net-6.9.11.msi
ISSUE 3:
MySQL issue - "error 6003: The value for column 'IsPrimaryKey' in table 'TableDetails' is DBNull." Specified cast is not valid.
[1 Jan 2016 15:27] "Noman Khan. Run the following command on the MySQL DB and then try if this works. set global optimizer_switch='derived_merge=off'" (on the user you will use. i.e root)
ISSUE 4:
Out of memory execption. Restart VisualStudio.
ISSUE 5:
If "MySQL" option doesnt display in the "Change Data source" listbox. Install the Visual Studio MySQL Plugin
Can't use a MySQL connection for entity framework 6
NOTE:
EntityFrameworkPowerToolsBeta4 is not built for VS2015 or 17. The installer version must be modified for it to install
How to use Entity Framework Power Tools in Visual Studio 2015?
http://thedatafarm.com/data-access/installing-ef-power-tools-into-vs2015/
NOTE:
You can view the Generated SQL query by debugging/break on the object prior to deferred execution of the query.
You can Use Aliases to map to other db's
Watch out for poor pluralization rules like "Statu" to "Status"
Check out https://us.visualstudiogallery.msdn.microsoft.com/ee4fcff9-0c4c-4179-afd9-7a2fb90f5838/view/Discussions
This seems to be more configurable and better supported. But only works for MSSQL?

How do I change an entity framework project to use Microsoft SQL Server

I am trying to debug a program using Entity Framework code first on my personal (work) computer.
We have recently had a domain migration, meaning that the user I log in as now is not the same that I used before. This caused me to loose access to the databases I had on the computer. To get around this, I have uninstalled everything to do with Microsoft SQL Server on the computer, and installed the latest version of Microsoft SQL Server, 2014 - 12.0.4213.0 . I then restored the database I need.
When I first tried to run the program, Visual Studio complained that the project is set up to use SQL Server Express, which was not installed. The recommended solution is to change the project to use SQL Server instead. To do this, I must click on "the database file" and follow the instructions. I have looked through the entire solution. There is a great many files, but I found no good candidate for "the database file."
It seems that my Google fu is not strong enough to find anything about this. So my question is: how do I change the project to use SQL Server?
I also have a second, related question. I tried to solve the problem by installing SQL Server Express. However, when I try to restore the database to this, no base appears in the drop down list. When I try to run the program now, I get another error:
Unable to create the file 'c:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL\DATA\Timelønsblanket.mdf' because it already exists.
I guess that this is also why I cannot restore the database. What I have found in websearches warns that I should not manually delete .mdf files.
Any advice on what to do?
I have solved the problem. All that was needed was a correct connection string. No need to find a "database file".

Visual Studio thinks correct SQL syntax is incorrect

In Visual Studio 2013, I have created a database project and imported an existing database. At first all was fine, and the project built and produced create scripts.
However, now Visual Studio seems to think that there are SQL syntax errors, returning several SQL46010: Incorrect syntax near: errors. These are all from code generated by VS - I have not written any of it.
Example 1:
ALTER ROLE [db_owner] ADD MEMBER [SomeUser];
SQL46010: Incorrect syntax near ADD.
Example 2:
DECLARE #Foo NVARCHAR(7) = 'abcdefg';
SQL46010: Incorrect syntax near =.
If I copy/paste the code into SSMS, everything works fine.
Unfortunately, these prevent the project from building, which means I can't publish. Since they are errors, not warnings, I cannot set them to be ignored in the project settings.
A workaround exists where I can set the problem files' Build Action to None, but I need these files included when I publish.
I have tried:
Deleting and re-adding the same code
Copy/pasting code to new SQL file
Closing and reopening the solution
Closing and reopening Visual Studio
Updating Microsoft SQL Server Data Tools (SSDT)
Updating Visual Studio
The closest problem I have been able to find is this MSDN thread from 2012, stating that there is a bug SSDT SQL parser (which prompted me to try updating SSDT).
There is a setting in the project properties called Target platform that tells VS what version of SQL Server to check the syntax against.
These are relatively new additions to the T-SQL syntax, and they might not work if the syntax was set to e.g. SQL Server 2005.
Old thread but this did catch me out so I thought I'd share my experience, the documentation for ALTER ROLE seems to indicate that it is supported on SQL 2008 when in fact only part of the functionality is. You can use Alter Role to change the name of a Role i.e. ALTER ROLE [ROLE NAME] WITH [NEW ROLE NAME]
But to add or remove members from the role it is necessary to use the old (and now deprecated) stored procedure sp_addrolememeber i.e. sp_addrolemember 'Role Name', 'User Name'.
As Aaroninus points out if you target SQL 2012 or later this will not report as an error.
In my case I was adding already existing post deployment script(.sql file) by clicking on a folder named "Reference Data" ==>Add Existing Item==>Select List of .sql files including the Script.PostDeployment1.sql file. On pressing F5 it was giving following error:
SQL46010: Incorrect syntax near :.
contents of sql file were :
:r ".\Customer.data.sql"
GO
:r ".\Product.data.sql"
GO
:r ".\OrderType.data.sql"
GO
:r ".\Orders.data.sql"
GO
Solution:
Post Deployment script should be created using VS.In existing project,open Visual studio and add post deployment script by clicking on : Add==>New Item ==>Script ==>Post Deployment Script ==>.PostDeployment1.sql.After creating PostDeployment1.sql file simply copy paste your content an then press F5..PostDeployment1.sql should execute correctly without any error.
having to set a flag in the project is really stupid since i've got ddl sql scripts in both oracle and mssql inside my c# class project.