SSDT publish script recreates procedures with no changes

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-08 10:30:28

问题


I have a database imported into a .sqlproj, and a .publish.xml publish profile which publishes changes to a remote DB.

My understanding is that when I right click -> Publish -> Generate Script, it should calculate the diff between the local definitions and the remote DB, and generate a script to bring the remote DB in line.

This all seems to work OK, however, the script it generates always contains ALTER FUNCTION and ALTER PROCEDURE statements for the same 40 or so functions and procedures (out of a total of around 1000 defined), whether they have changed or not. When I compare the ALTER statements with the Script Function as -> ALTER to script in SSMS, they are exactly the same.

So my question is: Why does VS think these are different, or why would it recreate them anyway if they are the same?

Notes:

  • The functions are not special - some of them are as simple as defining a varchar, setting it to a value and returning it.
  • I've tried running the ALTER scripts into the database, but they continue to be generated.
  • I've checked the properties (right click -> properties) in SSMS but can't see anything obviously different about those it always recreates and those it does not.
  • My publish profile is the bog standard one.

Thanks


回答1:


Update:

By renaming the .dacpac as a .zip and extracting the model.xml I could see the <HeaderContents> of some of the procedures had &#xA; (LF - the Line Feed character) in them.

This made me realise that for some reason all my .SQL files had unix line endings (LF) instead of windows line endings (CR LF). Converting all the files to window line endings (using notepad++) solved the problem.

Original:

OK, it looks like most of them are due to string constants in the scripts containing new line characters. Replacing them with their manually defined characters means they're not longer picked up for redeployment. i.e.

SET @doesnt_work = 
'FOO
BAR'

can be replaced with

SET @works = 'FOO'  + CHAR(13) + CHAR(10) + 'BAR'

Note: This is more of a workaround than a solution, and hopefully someone can suggest a better way to do this...



来源:https://stackoverflow.com/questions/39997071/ssdt-publish-script-recreates-procedures-with-no-changes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!