I have a .sqlproj (Microsoft SQL Project) folder (Git repository) which I'd like to Publish to a live database instance using command line tools.
My colleague currently does this manually using Visual Studio:
Right-click on Solution then select Rebuild solution
Right-click on database project then select Publish
Load a profile from a .XML file (containing database connection string and a few other options)
Hit Publish to build this database on to the server specified in .XML file
How can I replicate this using command line tools? Preferably I would use Linux, but I'm open to using Windows options too as long as the process is fully automated.
Thanks in advance
Related
I have an SSIS package that I am looking to save to a SQL Server database. In prior versions of Visual Studio, I had no issue doing this. I would go to:
File -> Save copy of package as
and it would give me the option to either save the package on the file system or to a SQL Server database.
Now the only option I get is to save to the file system.
How can I save to the SQL Server database again?
"Save Copy of Package as..." is only available if the SSIS Project is using the Package Deployment Model. By default, new project's use the Project Deployment Model.
To convert, right click on the Project and select "Convert to Package Deployment Model"
I have a DB project in Visual Studio and I need to deploy it to a remote system as a pre-packaged script (or similar) as a new database.
The Publish option will generate a .publish SQL script but only if you supply a connection first, and the script includes machine-local information e.g. logging paths.
I want something I can copy onto the DB-server machine running SSMS and it will create the DB. What is the proper way to do this, I see I also have DAC and DLL files emitted during build.
What is the proper way to do this?
Connect to a server that doesn't have any version of your database, and publish. Publish calculates an incremental deployment, so it needs to see the current state of the target SQL Server.
I need to automate SQL Server DB deployment using Azure DevOps. I don't want to give any alter statement. I will have a folder structure with tables, stored procedures, views & functions in repository. Every folder will contain only create scripts. Is there anyway to create DacPac file with that folder structure or any other way, other than DacPac deployment using that folder structure?
Note: I don't want to create DB project using Visual Studio. And I don't want to create a DacPac file directly from SQL Server Management Studio and checkin the same to source control. And I am not in a situation to pay for license.
You can try to use SQL Database Projects extension in Azure Data Sudio. It supports VS SQL Database Project and it supports builds from the command line: Build a database project from command line
What you describe is the database project. A dacpac is the build output of a Database project. There are no licenses involved. All the tools that produce dacpac files are free:
Both SQL Server Data Tools (SSDT) and SQL Server Management Studio (SSMS) are free, standalone downloads.
You can install SSDT on top of Visual Studio Community which is also free.
Azure Data Studio supports database projects. Also free, open source and works on Mac and Linux. I'm using it on Mac to edit database projects, using a SQL Server Developer Edition in a Docker container.
The sqlpackage command-line tool can extract a dacpac from an existing database, publish it or generate a migration script. Also free and a standalone download
I am having a hard time figuring how to actually create or even open a DAC application with Visual Studio 2012. I am using SQL Server 2012. I have SSDT installed.
Creating from Visual Studio:
According to online documentation I should be able to see a project template with the name "Data Tier Application" but all I see is SQL Server Database Project. Are they the same?
Creating from SSMS:
In an online video the presenter is using SSMS -> Database -> Right Click -> Create Project menu item, and after the wizard a VS project is popped open. I do not have this menu item, what I have is Tasks -> Export as Data Tier Application. This creates the DACPAC file but not the VS project, and I could not figure out how to open a dacpac from VS.
The purpose of a DACPAC is to provide a portable representation of a database schema, that can be used to deploy that schema to a database, import it into a database project in Visual Studio, and be used in functions like Schema Compare to examine differences between different sources. Whenever you build a database project in Visual Studio a .dacpac file will be generated, and this can then be used to deploy the schema defined in that project to a database.
The best place for full information is the SSDT help, but I'll give you a quick summary.
If you already have a DACPAC, you can use it in VS in the following ways:
Import the schema into a project by right-clicking on the project in Solution Explorer and choosing "Import -> Data-tier Application (*.dacpac)". Then choose your dacpac, and the contents will be converted into SQL Scripts and added to the project
Publish the dacpac to a database by opening SQL Server Object Explorer, navigating to a server, right-clicking on Databases and choosing "Publish Data-tier Application..." This will publish the contents of a DACPAC up to a database on that server. You could update a database by right-clicking on a database in the Databases list. Note that if the SQL Server Object Explorer view isn't open, you can select "View -> SQL Server Object Explorer" to ensure it appears.
To create a DACPAC in Visual Studio, you can
Build a project. This creates a dacpac in the bin\Debug directory (assuming you build in Debug mode).
Snapshot a project. This creates a dacpac and saves it in the project. It's very useful to track point in time versions of your database schema and compare previous versions of the database to the latest definitions.
Right-click on a database in SQL Server Object Explorer and choose "Extract Data-tier Application..." This will create a dacpac that represents the database contents.
Finally I'm not sure what video you viewed, but it's possible they showed right-clicking on a DB in SQL Server Object Explorer and creating a project from there. That's a very common way to start development using a database project, since often you'll already have a database containing your schema. Generally the best practices would be to develop using a project, and use dacpacs (and possibly command line deployment tools like SqlPackage.exe) when deploying out to different environments such as your production servers (again dacpacs are great for transporting schema definitions and deploying them to different environments). Hope this helps answer your question!
I have installed a sample database, specifically Northwind from http://msdn.microsoft.com/en-us/library/8b6y4c7s.aspx.
After installing the .msi file, I dont see any Northwind database in my local sql express server when using SQL Server management studio. Am i missing a step? Do i have to run some script?
From the download page:
After downloading SQL2000SampleDb.msi, extract the sample database scripts by
double-clicking SQL2000SampleDb.msi. SQL2000SampleDb.msi will extract the
database scripts and this readme file into this
default folder:
C:\SQL Server 2000 Sample Databases
So it seems to me you have to go to that folder and execute the SQL files installed there for the database to be created.
you don't mention which msi file, but most of them seem to relate to a sample database.
Which database software are you using?
From the download page on the page you linked to:
After downloading SQL2000SampleDb.msi,
extract the sample database scripts by
double-clicking SQL2000SampleDb.msi.
SQL2000SampleDb.msi will extract the
database scripts and this readme file
into this default folder: C:\SQL
Server 2000 Sample Databases
I didn't download it to see what gets extracted, but I'm betting there's a script or two that you can run to create the database. Probably a *.sql, that you can open and run in a query window.
EDIT: I just downloaded and extracted. It looks like all you need to do is execute the contents of instnwnd.sql (which should be in C:\SQL Server 2000 Sample Databases). Open a new query window (in SSMS etc.), load the file, and press F5.