I am working on a sql database project in VS 2010. I know how to synchronize the schema, but what I want is this:
1. I have some data sql scripts that inserts data into some tables.
2. I want to when I click Deploy on the DB project to automatically deploy those data scripts and execute them on the sql server.
How to do this?
Thanks
You'll need to put the INSERT statements into a post deployment script.
Related
I'm working on an Angular / .Net core project, and I want to deploy it on my homemade server equipped with Windows Server 2016.
I'm stuck at figuring out the best way to create my database from my migrations files. I've seen some topics on stackoverflow about it, but I don't want to make mistakes on my server, so I'm asking for the best way to do that.
The first option I think is to install Visual Studio IDE on my server. Then I can open my project and run an Update-database command, which will read all migrations files and create database.
But I don't think I'm supposed to install Visual Studio on a server...
The second option is something I saw on StackOverflow. In my development environment, I can use the command dotnet ef migrations script, which will generate a script.
But I'm not sure where I should put this script. I think probably in Microsoft SQL Server Management studio, New query and put my script.
Could you please tell me the best way ?
you need dotnet sdk in order to use dotnet ef migrations script but you can use your development pc to connect to your remote SQL Server and do migrations. for this, just point your connection string to remote SQL Server and use either Update-Database or dotnet ef update database
Another solution exists and You can use SQL server Generate Script to query all your database objects and execute it on target SQL server.
The best way you can do "first create" of your database in production environment is to Generate Script from SSMS (SQL Server Management Studio) and run that script on production Db server. The reason of that is because your database is empty (you can put all of data in script) and you can easily change the name, etc.
After that, on new versions of your application, the best way is to use Update-Database -Script and save/add that script to your deployment scripts.
When you are preparing for go-live, try that scripts with ROLLBACK TRANSACTION, if something fails...
I'm developing a project with ASP.net-MVC and as it's Model first, it generates the .mdf and .ldf files of database automatically. and database is in version of 2014. when I wanted to upload it on host server they told me that they don't support upper version of 2012. so I need to migrate my data base from 2014 to 2012 version.
my data base is not that much big. and I follow this article
https://www.mssqltips.com/sqlservertip/2810/how-to-migrate-a-sql-server-database-to-a-lower-version/
step by step but no diffrence happend to my database version. its still Product Version:12.0.2000.8
really appreciate you'r help. thanks
You develop the database based on the Model First, so you have all control in generation /modifying the database.
You needn't to migrate the database, but in visual studio you can re-generate the database in sql server 2012.
To Generate the database in sql 2012, do the same steps you follow to generate database for sql 2014 in visual studio, just for reminding:
In the EDMX design surface, right click ->Generate database from the model
Follow the wizard and create a new connection to sql2012.
At end of the wizard, a new database is created in sql server 2012.
Sql script is also auto generated named e.g. model.edmx.sql including all DDL of the Entity and associations,...
Exute that script within VS, you can select the connection and executing the script in the new database server 2012.
For the data, you can use the bcp utility or the export wizard in SSMS.
Update:
In the Model First approach, you create a diagram that will be automatically converted to a coded model and the model is saved in EDMX (xml file).
If there is no EDMX in the project, it means that you didn't use the ModelFirst approach, but you may used a template of MVC project which auto generate database at the start of the project.
The benefit of the Model First is the ease of change and sync between development Environment and the production for future changes.
You can re-engineer your project and add ModelFirst approach even you created a database.
From there you can re-create the database in the sql server 2012.
I describe step by step tutorial to build your mode:
Building DataModel from Existing Database in EntityFramework 6 For ModelFirst Approach
Compatibility Level should be set to SQL Server 2012(110) before to following the steps https://www.mssqltips.com/sqlservertip/2810/how-to-migrate-a-sql-server-database-to-a-lower-version/
To change the compatibility level go to database properties->Options->Compatibility Level
When you run the output script, it should be run on the target server (2012). Backups on recent versions cannot be restored on earlier versions.
Take a look here
The setup will change your database from 2014 to 2012.
Can any one explain what actually happens in the background of SQL SERVER while a SSIS Package is being created.
what does SQL SERVER actually do to create a package?
Help would be appreciated.
You create a package using a tool such as Visual Studio. Sql Server is not involved at all.
There are multiple deployment options. If you deploy to a file system the package can be run with CMD, Powershell, a windows app... In this case, again, Sql Server is not involved until the package is run.
If you deploy to MSBD the package is stored there. This was called deploying to Sql before version 2012.
If you deploy to the Integration Services Catalog then info is stored in the SSISDB database.
There is plenty of information available on the specific details of these scenarios.
SSIS packages are just automated processes that gives us Interactive drag and drop interface and when we do that using particular tool for a particular purpose(say importing csv file into DB) it automatically creates all coding behind the scenes like query to create table and insert commands for inserting all data from csv to DB table.
I am working on creating a visual studio database solution so that i could deploy databases in a more managed manner. Following are the steps that i performed after adding some sample tables and SPs in the solution.
Deploy the database to my local machine (and a new database is created).
Add some mock data to the tables in SSMS.
Add couple of columns to one of the tables in the VS 2010 solution.
Build the solution and deploy the database again (this time it deploys only the changes made to the schema).
Verfiy that the existing data was intact and new columns have been added to the table schema.
Everything is working as expected till this point.
Now I delete the database manually which was created by the deployment.
Go to VS 2010 and deploy the solution (expecting that it should do a clean deployment of the database), however i get the following error :
------ Deploy started: Project: MyDatabase, Configuration: Debug Any CPU ------
Pre-Deploy: Starting script execution…
Pre-Deploy: Finished script execution.
MyDatabase.dacpac(0,0): Error :
-->Cannot upgrade the DAC for database MyDatabase, a database with that name does not exist. Specify a valid database name.
Is there any setting in my solution where i could specify that the deployment should do a clean install if the database does not exist?
Or
Do i need to write separate (database creation) scripts if the database does not exist?
I ran into this issue as well. I deleted the database and could not deploy again. Then I found this link. DAC application needs to be deleted in the SQL Server Management Studio.
http://msdn.microsoft.com/en-us/library/ee240822.aspx
To Delete a DAC application
In SQL Server Management Studio connect to the database
Expand the Management node.
Expand the Data-tier Applications node.
Right-click the DAC to be deleted, and then select Delete Data-tier Application…
Complete the wizard dialogs:
I deleted the application and was able to deploy again. I am still learning that DAC is application.
How do I allow an SSIS package to consume a Visual Studio 2005 or 2008 Database project which houses the creation scripts for the tables and other objects (note: this is not Visual Studio Database Edition - just Pro with Business Intelligence)?
The idea is to use this to recreate my test instance by building the schema from source safe and the data from prod.
I have access to both VS2005 and 2008 Pro and this is hitting Sql Server 2005 for both Prod and Test.
The short answer is, you cannot "allow an ssis package to consume a VS 2005 or 2008 db project". I am not sure why you want to use SSIS to run the create scripts. You can run the scripts from sqlcmd utility.
If you still want to use SSIS, this is what I would do:
create a deployment script (VS for DB Pro can do that)
create a package
in your control flow, use Execute Process Task and configure it to run sqlcmd with the script file as your input
You can call the scripts in the DB project through Execute SQL tasks in the SSIS package. However, there's not a direct way to consume them.