{"id":3524,"date":"2009-07-02T20:31:52","date_gmt":"2009-07-02T20:31:52","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/webdev\/2009\/07\/02\/vs2010-beta1-quotdelete-existing-objects-before-creatingquot-flag-for-db-deployment\/"},"modified":"2009-07-02T20:31:52","modified_gmt":"2009-07-02T20:31:52","slug":"vs2010-beta1-quotdelete-existing-objects-before-creatingquot-flag-for-db-deployment","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/dotnet\/vs2010-beta1-quotdelete-existing-objects-before-creatingquot-flag-for-db-deployment\/","title":{"rendered":"VS2010 Beta1 &quot;Delete existing objects before creating&quot; flag for DB Deployment"},"content":{"rendered":"<p>&#160;<\/p>\n<p>Here is an example of end to end scenario of the last blog <a href=\"http:\/\/blogs.msdn.com\/webdevtools\/archive\/2009\/06\/28\/vs2010-beta1-web-application-project-database-package-and-smo-options.aspx\">VS2010 Beta1 Web Application Project Database package and SMO options<\/a>. Here, we\u2019re going to package a web application and its database with \u201cDelete existing objects before creating\u201d flag, so that we can test the deploy multiple times without the need to drop the database each time after deployment.&#160; This feature should be useful for the daily QA testing.<\/p>\n<p>1. Create a Web Application Project<\/p>\n<p>2. Go to its property page, Deploy SQL property page, click Add to add an connection name.&#160; Select it, check \u201cPull data from an existing databases\u201d.&#160; Input a connection string for the source database.&#160; Input a connection string for the destination connection string.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/16\/2019\/02\/image_16.png\"><img decoding=\"async\" style=\"border-right-width: 0px;border-top-width: 0px;border-bottom-width: 0px;border-left-width: 0px\" title=\"image\" border=\"0\" alt=\"image\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2009\/07\/image_thumb_7.png\" width=\"609\" height=\"422\" \/><\/a> <\/p>\n<p>3. Saving the project.<\/p>\n<p>4. Looking for the supported SMO options from msdeploy IIS7 module.&#160; Start IIS7, and choose \u201cExport Application\u201d.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/16\/2019\/02\/image_14.png\"><img decoding=\"async\" style=\"border-right-width: 0px;border-top-width: 0px;border-bottom-width: 0px;border-left-width: 0px\" title=\"image\" border=\"0\" alt=\"image\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2009\/07\/image_thumb_6.png\" width=\"585\" height=\"404\" \/><\/a> <\/p>\n<p>5. Click \u201cAdd Components \u2026\u201d button.&#160; Add a new provider, choose dbFullSql.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/16\/2019\/02\/image_12.png\"><img decoding=\"async\" style=\"border-right-width: 0px;border-top-width: 0px;border-bottom-width: 0px;border-left-width: 0px\" title=\"image\" border=\"0\" alt=\"image\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2009\/07\/image_thumb_5.png\" width=\"462\" height=\"271\" \/><\/a> <\/p>\n<p>6. Click \u201c\u2026\u201d in the new provider\u2019s \u201cProvider Settings\u201d column, we\u2019ll see all the available SMO options.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/16\/2019\/02\/image_10.png\"><img decoding=\"async\" style=\"border-right-width: 0px;border-top-width: 0px;border-bottom-width: 0px;border-left-width: 0px\" title=\"image\" border=\"0\" alt=\"image\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2009\/07\/image_thumb_4.png\" width=\"448\" height=\"243\" \/><\/a> <\/p>\n<p>7. Set <strong>ScriptDropsFirst=\u201dTrue\u201d <\/strong>inside the project file\u2019s PreSource XML node (e.g. appName.vbproj\/csproj file), and reload it in VS.<\/p>\n<pre class=\"code\"><span style=\"color: blue\">&lt;<\/span><span style=\"color: #a31515\">PublishDatabaseSettings<\/span><span style=\"color: blue\">&gt;\n  &lt;<\/span><span style=\"color: #a31515\">Objects<\/span><span style=\"color: blue\">&gt;\n    &lt;<\/span><span style=\"color: #a31515\">ObjectGroup <\/span><span style=\"color: red\">Name<\/span><span style=\"color: blue\">=<\/span>&quot;<span style=\"color: blue\">NewConnection1<\/span>&quot; <span style=\"color: red\">Order<\/span><span style=\"color: blue\">=<\/span>&quot;<span style=\"color: blue\">1<\/span>&quot;<span style=\"color: blue\">&gt;\n      &lt;<\/span><span style=\"color: #a31515\">Destination <\/span><span style=\"color: red\">Path<\/span><span style=\"color: blue\">=<\/span>&quot;<span style=\"color: blue\">Data Source=1p18-fwg35%3bInitial Catalog=SimpleDB1_test1%3bIntegrated Security=True<\/span>&quot; <span style=\"color: blue\">\/&gt;\n      &lt;<\/span><span style=\"color: #a31515\">Object <\/span><span style=\"color: red\">Type<\/span><span style=\"color: blue\">=<\/span>&quot;<span style=\"color: blue\">dbFullSql<\/span>&quot;<span style=\"color: blue\">&gt;\n        &lt;<\/span><span style=\"color: #a31515\">PreSource <\/span><span style=\"color: red\">Path<\/span><span style=\"color: blue\">=<\/span>&quot;<span style=\"color: blue\">Data Source=1p18-fwg35%3bInitial Catalog=SimpleDB1%3bIntegrated Security=True<\/span>&quot; <span style=\"color: red\">ScriptSchema<\/span><span style=\"color: blue\">=<\/span>&quot;<span style=\"color: blue\">True<\/span>&quot; <span style=\"color: red\">ScriptData<\/span><span style=\"color: blue\">=<\/span>&quot;<span style=\"color: blue\">False<\/span>&quot; <span style=\"color: red\">SchemaQualify<\/span><span style=\"color: blue\">=<\/span>&quot;<span style=\"color: blue\">True<\/span>&quot; <strong><span style=\"color: red\">ScriptDropsFirst<\/span><span style=\"color: blue\">=<\/span>&quot;<span style=\"color: blue\">True<\/span>&quot;<\/strong> <span style=\"color: blue\">\/&gt;\n        &lt;<\/span><span style=\"color: #a31515\">Source <\/span><span style=\"color: red\">Path<\/span><span style=\"color: blue\">=<\/span>&quot;<span style=\"color: blue\">objDebugAutoScriptsNewConnection1_SchemaOnly.sql<\/span>&quot; <span style=\"color: blue\">\/&gt;\n      &lt;\/<\/span><span style=\"color: #a31515\">Object<\/span><span style=\"color: blue\">&gt;\n    &lt;\/<\/span><span style=\"color: #a31515\">ObjectGroup<\/span><span style=\"color: blue\">&gt;\n  &lt;\/<\/span><span style=\"color: #a31515\">Objects<\/span><span style=\"color: blue\">&gt;\n&lt;\/<\/span><span style=\"color: #a31515\">PublishDatabaseSettings<\/span><span style=\"color: blue\">&gt;<\/span><\/pre>\n<p>8. Package the project from command line: %projectDir%&gt;msbuild WebApplication2.vbproj \/target:package<\/p>\n<p>9. Read sample deploy command line batch file and set the environment: %projectDir%objdebugpackage&gt; WebApplication2.deploy.cmd<\/p>\n<p>set Path=%Path%;&quot;C:Program FilesIISMicrosoft Web Deploy&quot;<\/p>\n<p>10. Test the package deploy locally from command line: %projectDir%objdebugpackage&gt; WebApplication2.deploy.cmd \/y<\/p>\n<p>If you check the script created inside the package %projectDir%objdebugpackage%projectName%.zip file , you can see the sqlScript file inside with format like following:<\/p>\n<pre class=\"code\"><span style=\"color: blue\">IF  EXISTS <\/span>(<span style=\"color: blue\">SELECT <\/span>* <span style=\"color: blue\">FROM <\/span>sys.foreign_keys <span style=\"color: blue\">WHERE object_id <\/span>= <span style=\"color: blue\">OBJECT_ID<\/span>(N<span style=\"color: #a31515\">'[dbo].[FK_Products_Categories]'<\/span>) <span style=\"color: blue\">AND <\/span>parent_object_id = <span style=\"color: blue\">OBJECT_ID<\/span>(N<span style=\"color: #a31515\">'[dbo].[Products]'<\/span>))\n<span style=\"color: blue\">ALTER TABLE <\/span>[dbo].[Products] <span style=\"color: blue\">DROP CONSTRAINT <\/span>[FK_Products_Categories]\nGO\n<span style=\"color: blue\">IF  EXISTS <\/span>(<span style=\"color: blue\">SELECT <\/span>* <span style=\"color: blue\">FROM <\/span>sys.check_constraints <span style=\"color: blue\">WHERE object_id <\/span>= <span style=\"color: blue\">OBJECT_ID<\/span>(N<span style=\"color: #a31515\">'[dbo].[CK_Products_UnitPrice]'<\/span>) <span style=\"color: blue\">AND <\/span>parent_object_id = <span style=\"color: blue\">OBJECT_ID<\/span>(N<span style=\"color: #a31515\">'[dbo].[Products]'<\/span>))\n<span style=\"color: blue\">ALTER TABLE <\/span>[dbo].[Products] <span style=\"color: blue\">DROP CONSTRAINT <\/span>[CK_Products_UnitPrice]\nGO\n<span style=\"color: blue\">IF  EXISTS <\/span>(<span style=\"color: blue\">SELECT <\/span>* <span style=\"color: blue\">FROM <\/span>sys.check_constraints <span style=\"color: blue\">WHERE object_id <\/span>= <span style=\"color: blue\">OBJECT_ID<\/span>(N<span style=\"color: #a31515\">'[dbo].[CK_Products_UnitsInStock]'<\/span>) <span style=\"color: blue\">AND <\/span>parent_object_id = <span style=\"color: blue\">OBJECT_ID<\/span>(N<span style=\"color: #a31515\">'[dbo].[Products]'<\/span>))\n<span style=\"color: blue\">ALTER TABLE <\/span>[dbo].[Products] <span style=\"color: blue\">DROP CONSTRAINT <\/span>[CK_Products_UnitsInStock]\nGO\n<span style=\"color: blue\">IF  EXISTS <\/span>(<span style=\"color: blue\">SELECT <\/span>* <span style=\"color: blue\">FROM <\/span>sys.objects <span style=\"color: blue\">WHERE object_id <\/span>= <span style=\"color: blue\">OBJECT_ID<\/span>(N<span style=\"color: #a31515\">'[dbo].[TotalProductsCost]'<\/span>) <span style=\"color: blue\">AND <\/span>type <span style=\"color: blue\">in <\/span>(N<span style=\"color: #a31515\">'P'<\/span>, N<span style=\"color: #a31515\">'PC'<\/span>))\n<span style=\"color: blue\">DROP PROCEDURE <\/span>[dbo].[TotalProductsCost]\nGO\n<span style=\"color: blue\">IF  EXISTS <\/span>(<span style=\"color: blue\">SELECT <\/span>* <span style=\"color: blue\">FROM <\/span>sys.objects <span style=\"color: blue\">WHERE object_id <\/span>= <span style=\"color: blue\">OBJECT_ID<\/span>(N<span style=\"color: #a31515\">'[dbo].[ShowCategories]'<\/span>) <span style=\"color: blue\">AND <\/span>type <span style=\"color: blue\">in <\/span>(N<span style=\"color: #a31515\">'FN'<\/span>, N<span style=\"color: #a31515\">'IF'<\/span>, N<span style=\"color: #a31515\">'TF'<\/span>, N<span style=\"color: #a31515\">'FS'<\/span>, N<span style=\"color: #a31515\">'FT'<\/span>))\n<span style=\"color: blue\">DROP FUNCTION <\/span>[dbo].[ShowCategories]\nGO\n<span style=\"color: blue\">IF  EXISTS <\/span>(<span style=\"color: blue\">SELECT <\/span>* <span style=\"color: blue\">FROM <\/span>sys.objects <span style=\"color: blue\">WHERE object_id <\/span>= <span style=\"color: blue\">OBJECT_ID<\/span>(N<span style=\"color: #a31515\">'[dbo].[ShowProducts]'<\/span>) <span style=\"color: blue\">AND <\/span>type <span style=\"color: blue\">in <\/span>(N<span style=\"color: #a31515\">'FN'<\/span>, N<span style=\"color: #a31515\">'IF'<\/span>, N<span style=\"color: #a31515\">'TF'<\/span>, N<span style=\"color: #a31515\">'FS'<\/span>, N<span style=\"color: #a31515\">'FT'<\/span>))\n<span style=\"color: blue\">DROP FUNCTION <\/span>[dbo].[ShowProducts]\nGO\n<span style=\"color: blue\">IF  EXISTS <\/span>(<span style=\"color: blue\">SELECT <\/span>* <span style=\"color: blue\">FROM <\/span>sys.views <span style=\"color: blue\">WHERE object_id <\/span>= <span style=\"color: blue\">OBJECT_ID<\/span>(N<span style=\"color: #a31515\">'[dbo].[ProductsPerCat]'<\/span>))\n<span style=\"color: blue\">DROP VIEW <\/span>[dbo].[ProductsPerCat]\nGO\n<span style=\"color: blue\">IF  EXISTS <\/span>(<span style=\"color: blue\">SELECT <\/span>* <span style=\"color: blue\">FROM <\/span>sys.objects <span style=\"color: blue\">WHERE object_id <\/span>= <span style=\"color: blue\">OBJECT_ID<\/span>(N<span style=\"color: #a31515\">'[dbo].[Products]'<\/span>) <span style=\"color: blue\">AND <\/span>type <span style=\"color: blue\">in <\/span>(N<span style=\"color: #a31515\">'U'<\/span>))\n<span style=\"color: blue\">DROP TABLE <\/span>[dbo].[Products]\nGO\n<span style=\"color: blue\">IF  EXISTS <\/span>(<span style=\"color: blue\">SELECT <\/span>* <span style=\"color: blue\">FROM <\/span>sys.objects <span style=\"color: blue\">WHERE object_id <\/span>= <span style=\"color: blue\">OBJECT_ID<\/span>(N<span style=\"color: #a31515\">'[dbo].[Categories]'<\/span>) <span style=\"color: blue\">AND <\/span>type <span style=\"color: blue\">in <\/span>(N<span style=\"color: #a31515\">'U'<\/span>))\n<span style=\"color: blue\">DROP TABLE <\/span>[dbo].[Categories]\nGO\n<span style=\"color: blue\">IF  EXISTS <\/span>(<span style=\"color: blue\">SELECT <\/span>* <span style=\"color: blue\">FROM <\/span>sys.types st <span style=\"color: blue\">JOIN <\/span>sys.schemas ss <span style=\"color: blue\">ON <\/span>st.schema_id = ss.schema_id <span style=\"color: blue\">WHERE <\/span>st.name = N<span style=\"color: #a31515\">'ExpireDate' <\/span><span style=\"color: blue\">AND <\/span>ss.name = N<span style=\"color: #a31515\">'dbo'<\/span>)\n<span style=\"color: blue\">DROP <\/span>TYPE [dbo].[ExpireDate]\nGO\n<span style=\"color: blue\">CREATE <\/span>TYPE [dbo].[ExpireDate] <span style=\"color: blue\">FROM <\/span>[datetime] <span style=\"color: blue\">NULL\n<\/span>GO\n<span style=\"color: blue\">SET <\/span>ANSI_NULLS <span style=\"color: blue\">ON\n<\/span>GO\n<span style=\"color: blue\">SET QUOTED_IDENTIFIER ON\n<\/span>GO\n<span style=\"color: blue\">CREATE TABLE <\/span>[dbo].[Categories](\n    [CategoryID] [int] <span style=\"color: blue\">IDENTITY<\/span>(1,1) <span style=\"color: blue\">NOT NULL<\/span>,\n    [CategoryName] [nvarchar](15) <span style=\"color: blue\">COLLATE <\/span>SQL_Latin1_General_CP1_CI_AS <span style=\"color: blue\">NOT NULL<\/span>,\n    [Description] [ntext] <span style=\"color: blue\">COLLATE <\/span>SQL_Latin1_General_CP1_CI_AS <span style=\"color: blue\">NULL<\/span>,\n <span style=\"color: blue\">CONSTRAINT <\/span>[PK_Categories] <span style=\"color: blue\">PRIMARY KEY CLUSTERED \n<\/span>(\n    [CategoryID] <span style=\"color: blue\">ASC\n<\/span>)<span style=\"color: blue\">WITH <\/span>(PAD_INDEX  = <span style=\"color: blue\">OFF<\/span>, STATISTICS_NORECOMPUTE  = <span style=\"color: blue\">OFF<\/span>, IGNORE_DUP_KEY = <span style=\"color: blue\">OFF<\/span>, ALLOW_ROW_LOCKS  = <span style=\"color: blue\">ON<\/span>, ALLOW_PAGE_LOCKS  = <span style=\"color: blue\">ON<\/span>)\n)<\/pre>\n<p>\u2026<\/p>\n<p>You can see, choose a right SMO option is not trivial.&#160; There are many SMO options, combining of which may have different effects.&#160; We do need some trial and errors to apply the right SMO option for advanced usage.<\/p>\n<p>Xinyang Qiu \n  <br \/>SDETII <\/p>\n<p>Visual Studio Web Tools<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#160; Here is an example of end to end scenario of the last blog VS2010 Beta1 Web Application Project Database package and SMO options. Here, we\u2019re going to package a web application and its database with \u201cDelete existing objects before creating\u201d flag, so that we can test the deploy multiple times without the need to [&hellip;]<\/p>\n","protected":false},"author":404,"featured_media":58792,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[197],"tags":[31,7341,7336,7323,7329],"class_list":["post-3524","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-aspnet","tag-asp-net","tag-database","tag-msdeploy","tag-visual-studio-2010","tag-web-deployment"],"acf":[],"blog_post_summary":"<p>&#160; Here is an example of end to end scenario of the last blog VS2010 Beta1 Web Application Project Database package and SMO options. Here, we\u2019re going to package a web application and its database with \u201cDelete existing objects before creating\u201d flag, so that we can test the deploy multiple times without the need to [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/3524","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/users\/404"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/comments?post=3524"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/3524\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media\/58792"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media?parent=3524"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/categories?post=3524"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/tags?post=3524"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}