Sumant
Sumant

Reputation: 964

Dacpac deployment in azure refers value as invalid column name

I am trying to deploy dacpac where i am passing arguments as $(name)="dev".

and in pre-deployment script have below code.

DECLARE @SQL VARCHAR(254);
BEGIN
    SET @SQL = 'INSERT INTO [dbo].[tblTest] (Id, name) VALUES (2, '''+$(name)+''');'
    EXEC(@SQL)
END

Now when running above query i am getting "Error SQL72014: .Net SqlClient Data Provider: Msg 207, Level 16, State 1, Line 1 Invalid column name 'dev'"

Here i am not sure what is wrong. need help to fix it.

Upvotes: 2

Views: 323

Answers (1)

wBob
wBob

Reputation: 14379

DACPAC deployments use sqlcmd variables so you do not have to treat it like a SQL variable. You do not have to concatenate it. This should work:

DECLARE @SQL VARCHAR(254);
BEGIN
    SET @SQL = 'INSERT INTO [dbo].[tblTest] (Id, name) VALUES (2, ''$(name)'');'
    EXEC(@SQL)
END

Upvotes: 1

Related Questions