We currently use TFS 2010 for our VS applications and our SQL code. For SQL we have every stored procedure stored in different text files e.g."spname.sql" and we alter these files and then apply them to the Dev server.
When it comes to testing we then do a branchcompare to compare the DEV branch to the UAT branch to get a list of the .sql files that are different.
Question is, is there a way to export out the files in the list from the dev branch so we can them apply all the SQL code that has changed to the UAT server?
(We do table alters / updates etc in a "rollout" type script).
Thanks
When you do a compare in Visual Studio (with SSDT), you can choose to create a script instead of deploying. Or you could use powershell Get-TfsItemHistory with -Version to get the file list and then use that list to get the source.
Related
I have a DACPAC SQL Server project that I edit in Visual Studio. I then have a SQL script for a table value function. How can I then embed the SQL script into the DACPAC project? I can't find any tutorial on how to make the folder and folder name, and how to set up the SQL file.
Does anyone know?
Creating folders isn't actually a requirement. When you build the project all objects represented in the project file will be added to the resulting DACPAC. Folders are merely a way to organize your files.
Generally speaking, your folder structure within the SQL DB project will look something like this:
Schema1
Functions
SomeFunc.sql
OtherFunc.sql
Stored Procedures
SomeProc.sql
OtherProc.sql
Tables
SomeTable.sql
OtherTable.sql
Views
SomeView.sql
OtherView.sql
Schema2
Functions
SomeFunc.sql
OtherFunc.sql
Stored Procedures
SomeProc.sql
OtherProc.sql
Tables
SomeTable.sql
OtherTable.sql
Views
SomeView.sql
OtherView.sql
. . . etc . . .
NOTE: if you create your function in a SQL Server DB, you can then jump back into Visual Studio and use Tools >> SQL Server >> Schema Compare to import your function into the project. Visual Studio will create the folders for you.
I am trying to create a database from my TFS project using SQL Compare.
Currently we compare our Database project to a CI database using the Compare tool in Visual Studio however, I have been asked to make this eventually run as a build step as part of the automated deployment.
Problem* SQL Compare will not recognize the database assembly file generated within visual studio. Therefore some computed columns that use clr functions fail on deployment.
I had success using SQL Compare to script a previously scripted Database to a 'Scripts Folder'. Next I pointed my SQL Compare left side to that new 'Scripts Folder' and right side at a new Database and the Assembly file was detected on the left side.
I have then tried copying the database assembly file to the visual studio database project location with no luck.
I unpacked the generated file 'Database.xxx.dacpac' file to a folder and set my Left side compare in SQL Compare to that. SQL Compare complains about "Scripts folder found with missing metadata file". There were other errors after I hit 'Compare' but I ignored them. However my assembly file showed up!
Is this supposed to be the correct process? assuming I remove all the warnings?
I expect to be able to compare my database project file in visual studio to a fresh database and update it within SQL Compare
Right click on your Database project file in the Solution Explorer
Go to build - and look up the location of 'Build Output Path' find the 'database.dacpac' file
Option A: double click and unpack the .dacpac file. In SQL Compare use option 'Script Folder' and use that newly created folder as a source, you can then create a database from your visual studio database project. SQL Compare - using DACPAC file
Option B: Use command line and SSMS application sqlpackage.exe to create database directly from the dacpac file without extracting.DACPAC Deployment using command line
Option C: Right click on database you want to upgrade in SSMS - and click on Tasks->'Upgrade Data-tier Application'. Use the DACPAC file as the source.
I tried to generate the script by query because I want create easily and same settings. I checked MSdoc but there is no method.
I use SSMS v17.6, SQLServer2016(SP2) on WindowsServer2012 R2 Standard.
By the GUI, DB right click=>Task=>generate scripts=>select database objects and set some settings.
I want to generate by query.
You can follow below steps to automate the creation of a database.
First export the database as a dapac using Export Data Tier Application
Install SQLPackage.exe in the environment where you are planning to carry out the deployment. You can download sqlpackage.exe download path . It will be used to automate the generation of scripts from DACPAC.
Once you have the DACPAC of the database, you can publish the same to any environment. The caveat is, Sqlpackage.exe generates incremental script, comparing against the target datatbase. If you want complete CREATE script, then you can point against any empty database or system database like master to generate incremental CREATE scripts(here it will be complete database script, as target is empty database). The generated script will be present in the output path (here, it is C:\temp)
Note: we are setting parameter (DropObjectsNotInSource to false), to avoid generation of drop objects of the target database, which are
missing in source DACPAC.
"<Path>\SqlPackage.exe"
/Action:script
/SourceFile:“<Path>\Database.dacpac”
/TargetDatabaseName:master
/TargetServerName:"localhost"
/OutputPath:C:\temp
/p:DropObjectsNotInSource:false
UPDATE
I see that, now there is a tool mssql-scripter(currently in preview) to carry out the same activity of Generate Scripts wizard of SQL Server Management Studio. You can see about the tool here: https://github.com/Microsoft/mssql-scripter
I have a SQL project in my .Net project in Visual Studio 2010. I added it to my solution because I thought it will help me to create all the database objects in more environment without difficulties.
My scope is to create/define the database objects (tables and stored procedures) in more computers, easily.For this purpose I created an Sql project in visual studio and I added for each table and stored procedure the creation script in this project. Now I have 30 scripts and I'd like to run it on a new sql instance.
If I open each sql file I have, in visual studio, an toolbat that allows me to tun the opened file on a sql instance (I have an connect button) and this generates the proper object (table or SP).
The question is: how do I do to run all the files in this project in one click. How to create all the objects in one click? Now I have about 30 scripts to run, and I need a proper way.
The way I tried to do it was to set as default project the sql project and to press run (F5), but then I got some strange compilation errors in sql files, errors witch didn't was there when I run (execute) each script individually.
Here is the right click menu for this project (No Run, Publish or something else!):
I tried to use from that menu the Deploy command. The bad news (for me) is that I got this on that command:
I don't have any error in my sql scripts, each one runs correctly.
Thank you.
Use need to deploy your project onto a database thus use the Deploy menu item.
The way database projects work, is that they compare the schema in the project to the schema at the destination.
What this means is you shouldn't have an use statements, or alter statements, ect...
What does one of those procs look like that is throwing the error?
I have a Visual Studio 2010 Database project, from which I want to generate a script
that simply puts up this database to another machine. The problem is that i can't find a
solution for this.
As I started the project, I imported the shema from a database on my development pc.
The Schema Objects were generated and all tables and scripts where under 'Schema Objects -> Schemas -> dbo'. Over the time, some things changed, some where added. And by using right-click -> deploy,
the changes were made to my local database successfully.
But now I want to deploy to another machine. The problem is, that in the release folder of the project, there is only a xml dbschema file containing all tables and scripts that i can't import
with sql management studio (or i just can't find out how) and the a deployment script which is nothing more than some checks followed by the pre- and post- deployment script, but without any tables or scripts in it.
So please, how do i export the database from Visual Studio, so i can easily put it up on another machine?
Marks--
You likely have already resolved this, but I thought I should answer your questions for the benefit of others.
Yes, you can deploy from Visual Studio to different machines. You can also do it from the command line, using VSDBCMD. And you can create a WIX project to give a wizard for others to install it with.
If you can connect to the target database from your dev PC, you can deploy to it. To do this:
Select another Configuration from the Solution Configuration drop down. Normally, the Project will come with "Debug" and "Release" baked in. You can add another configuration to allow you to deploy to various targets by clicking "Configuration Manager."
Right-click your Project and select 'Properties', or simply double-click Properties under the project.
Click the Deploy tab. Notice that the Configuration: drop-down shows the same selected configuration as "active."
Change the Deploy Action to "Create a deployment script (.sql) and deploy to the database."
Next to Target Connection String, click "Edit" and use the dialog to create your deployment connection to the target database.
Fill in the Target database name, if different.
For each Deployment Configuration (e.g., Debug, Release, etc.), you will probably want a separate Deployment configuration file. If you click "New," you can create one for the current configuration. The new file will open, and you can check and uncheck important things about the deployment.
Note: If you check Always re-create the database, the script will DROP and CREATE your database. You will lose all your data on the target! Be careful what you select here. Most people leave that unchecked for a Production target. I check it for Development or Local because I want a fresh copy there.
Save your changes to the file and to Properties.
To deploy to the target, be sure to select the correct Configuration. Click Build/Deploy [My Database Name]. You probably should experiment with this so you are familiar with how it works before trying it on a live environment.
Good practices: build a similar environment to production ("Staging") and deploy there first, to test the deployment, and always back up the database before deploying, in case something goes wrong.
For more info, please see:
Working with Database Projects
Walkthrough: Put an Existing Database Schema Under Version Control
Visual Studio 2010 SQL Server Database Projects
Is it's possible to point your Visual Studio to your new target database? 1. Properties of your Database project, Deploy tab, set the fields in Target Database Settings.
Now when you generate a deploy script, the resulting SQL file will be the various CREATe / ALTER / DROP etc that will align the target database with your schema.
You could always create an empty database and then do a schema compare in Visual Studio between your database project and the new empty database. You can amend the generated schema update script to also create the database (since the script will be to update an existing empty database)