Customize deploy scripts for Visual Studio 2010 Database project - visual-studio-2010

The deployment scripts generated by a visual Studio 2010 Database project won't work for me. I need to include them in an MSI that will be shipped to many different customers to both upgrade and create new databases.
Looking through the Microsoft.Data.Schema... namespaces I see many possibilities for customizing the generation of the deployment scripts, DeploymentScriptGenerator, ExtensionManager etc. etc. It really looks like it was designed to be extensible and to support any database.
What I can't find is any sort of "getting started" documentation or samples. Has anyone done something like this?

Visual Studio Data Projects use two phases of deployment.
The deployment files created by building the database project is really just a package of metadata that describes the desired final state of of the database, but with no knowledge of where is going to be deployed or whether it is a new database or existing database.
The second part is actually executing the deployment package against a specific database, either existing or new. To do that, Visual Studio has to run a diff against the database and the deployment package, and determine which changes need to be applied, and generate the script necessary to apply those changes.
So the problem you have is that if you include the first part in your MSI, you need something running on the end user's machine to apply those changes to an unknown number of unknown databases out in the field, and you can't really ship them Visual Studio.
Luckily MS includes a command line too (VSDBCMD.exe) which allows you to take that single deployment package and use it to apply changes to any database. This tool will do the same diff as Visual Studio and generate the SQL script necessary to create/upgrade that database (any actually run the script, if you so choose, based on command line parmaeters). See http://msdn.microsoft.com/en-us/library/dd193283.aspx for information about how to call it from the command line.
So I'd saw you ship that command line tool with your application (just make sure to double check the redistribution license to make sure this is OK) and have a custom action in your MSI (or some other utility) that executes it to apply the database changes. And also check the dependencies for the command line tool, I know it requires the SQL SMO objects, SQL Native Client, and probably a few other things. You'll want to make sure you MSI includes those as prerequisites.

Related

Oracle Developer Tools (ODT) with Visual Studio 2019

I'm using Visual Studio 2019, 16.11.9, with Oracle Developer Tools for Visual Studio, 19.3.2.0.
I can do a schema compare with my local database, but there are a number of issues I have noticed which I can't have following through to deployment in test or production. I just wondered if I am doing something wrong or if these issues are limitation of the extension.
Using schema compare generated change scripts only ever drop and rebuild an existing table, never alter it. This obviously deletes all the data in the table too. How do I change this?
Whenever I do a database clean build I have to run the schema compare, or build script, multiple times as the tool doesn't order the build based on dependencies. Surely this is my setup as otherwise this is a HUGE oversight!
Any help welcome.

How to save a SQL Server Maintenance Plan within a Visual Studio Database Project

Having created a SQL Server maintenance plan in a SQL Server 2008 R2 instance, how can I import the definitions into a Visual Studio 2013 SSDT database project?
I don't mind using pre- and post-deployment scripts if that helps but I want it to be in a database project and to be able to build the project in VS and then to be able to deploy either a new instance of the plan, or to be able to synchronize an existing plan instance with the definitions in the database project. Also, drop and re-create is entirely acceptable.
Does anyone else already know how to do that ?
First of all maintenance plans are not supported by SSDT.
You can export it manually as an xml template file and then try to write some sql/batch post deploy scripts to deploy it.
You can find general instruction here (read comments also): https://robertbigec.wordpress.com/2013/10/03/automating-deployment-of-sql-server-maintenance-plans/
One note: The exported xml template contains some specific values such as server name or path to backup/log file locations. You might want to write custom script to get these values from target machine and replace it in the xml file.

Attach and configure ms sql server database using installation package

i have some Db steps (attach database, adding and configure a new login, configure roles) and i want to automize it using installation package. Right now in project we are using standard Visual studio installer. Can i implement db steps using standard visual studio intaller (custom actions or something else)? Or maybe i should use some others installers like Install shield, Wix?
As far as I know Visual Studio setup project doesn't offer this functionality out of the box (although, my experience with it is tiny). Also, it is not a good idea to implement it all from scratch in a custom action - it is really the last resort.
Other vendors, at least those you mentioned, do offer this. if you decide to move to one of those, keep in mind the learning curve, which will take some of your time (for WiX is probably more). However, if the VS setup project is quite small and simple, it might be a good idea to move at this point, considering the fact that VS setup project type was deprecated by Microsoft.
For DB configuration you may create SQL script which can be installed with an application or into temp directory and feed it to whatever consumes sql scripts in mssql (in oracle its sqlplus). Not sure about visual studio but that's how I saw in one project for InstallShield.

Visual Studio 2008 Database project Deployment Baseline

I have a question about creating a deployment script using a database project in Visual studio 2008.
In a more traditional project we would create a deployment script that would create the DB and the initial objects for the first deployment. This would become the baseline.
Any additional objects would be scripted as ALTER statements. Each statement would check for the existence of the object, giving a re runnable database deployment script.
I want to be able to do the same thing with the database project, but it currently analyses the database and creates a script to take it from its current state to where the project specifies it should be. This is fine for local deployment, but I cannot use this to deploy to production, as they require a re runnable script that will not loose any data in the live system.
My first idea was to have a copy of the database that matches live, and then point the project to it to generate the statements for the deployment, but it does not seem very maintainable.
Does anyone have any idea about how achieve this?
Thanks
This is done by the Schema Compare option of the Database Edition of Visual Studio.
I Think you could find useful this link:
How to: Compare Database Schemas

Troubleshooting Plk Verification for Visual Studio Package in a VSIP Development Edition

I have a custom domain specific language project which was developed a while back, was deployed and run on the same machine inside the normal Visual Studio hive with no problems.
Server has been reinstalled and I'm trying to setup the environment again, so that the normal hive (which is a Visual Studio VSIP Edition SP1, with Visual Studio 2008 SDK) can use the DSL.
But the VSPackage is not loading. The Package Load Analyzer gives me a "Plk Verification" error. "Failed to read one of the following values for the package {guid} - Company Name, Package Guid, Product Name, Product Version, Minimum Edition."
Now I understand if I was deploying to a non VSIP Edition (or running devenv with /noVSIP) I would need to get a Plk from Microsoft, but since I am running on the same development machine where the DSL is also developed, there should be a Development Plk. Visual Studio also tells me at the start:
VSIP: Developer edition, all third-party packages allowed to load.
If I start the DSL project and debug it in the experimental hive then everything works fine, the package is loaded and all custom editors are displayed.
Any idea on how to further troubleshoot this?
Is it possible that the problem lies in that the DSL project was created on a different server and even though I've recompiled everything on the new server that the development key is somehow related to the server and is attached in the project files somewhere? If so, any idea where?
That is surprising. Since you have the VSIP SDK installed and are not using the /noVSIP switch, I too would expect the PLK-checking mechanism to be disabled (regardless of hive). However the package load analyzer is indicating a problem, and the package load analyzer is probably a better judge of whether VS will load a package than we are.
Have you tried actually applying a PLK to your VSPackage? It's not that hard to do. See here for how to get a PLK and then next topic for how to apply it to your code. You can rebuild and change your VSPackage as almost much as you want after applying a PLK. The only things you can't change are the four values hashed and baked into the PLK. (These are the product name, package name, version string and the minimum required edition of visual studio. These four values you give when you request a PLK must match those registered with your VSPackage.) And if you later decide to change one of those values, you can just get another PLK.

Resources