Question

I have a SQL Data Project that was created from the schema of my production database. It pulled in all the stored procedures into the project and I am trying to deploy the generated scripts to localdb for offline development.

The Issue is that it appears SQL Data Project is trying to validate the SQL script that it generated but its getting stuck at the first instance where it encounters a string containing $(.

Example 1 INSERT INTO mytable (text) VALUES ('$(')

This results in an error

Incorrect Syntax was encountered while $(' was being parsed.

Example 2 INSERT INTO mytable (text) VALUES ('$(this')

This results in an error

Incorrect Syntax was encountered while $(this' was being parsed.

Its seems like a bug in SQL Data Projects parse validation which is preventing the deployment from succeeding even though the scripts execute fine in SQL Management Studio.

UPDATE I tried some of the ideas and it seems the issue is specifically when SQL Data Project is parsing the string and encounters $(. In addition, everything that follows the $( in the string gets caught by the error up until the next instance of a single quote (Be it an escaping single quote or the end of the string single quote)

Was it helpful?

Solution

It seems that the script that SQL Data Tools generates for deployment of the database uses $() as a way of doing variable replacement. To correct the issue I had to replace the contents of the string with

CHAR(36) + '()' to represent $()

This way the parser wouldn't try to see it as a variable.

OTHER TIPS

You may try like this:-

INSERT INTO mytable (text) VALUES ('''I''''''m Sure this broke things''')

If you are inserting from SQL you may also try this:-

DECLARE @Value varchar(50)
SET @Value = 'I''m Sure this broke things'
INSERT INTO Table1 (Column1) VALUES (@Value)

If you are using ADO.NET then try like this:

using (SqlConnection conn = new SqlConnection(connectionString)) {
    conn.Open();
    using (SqlCommand command = conn.CreateCommand()) {
        command.CommandText = "INSERT INTO Table1 (text) VALUES (@Value)";

        command.Parameters.AddWithValue("@Value", "'I''m Sure this broke things'");

        command.ExecuteNonQuery();
    }
}
DECLARE @data varchar(50)
SET @data = 'I''m Sure this broke things'
INSERT INTO mytable (text) VALUES (@data)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top