Create database and add data during application installation - database

I have developed a windows form application. I have also created a database on sql server and added data to this database.
Now i want to install this application at clients place. I want to know the ways to move my created database on client's location. How can i do this during application installation? If i have to include database scripts in installation file and run it.how can i do it? If its a long process please specify links which helps me in accomplishing this task.
Thankyou very much.

Look at the GDR R2 database project (part of Visual Studio).
You can use this to reverese engineer your existing database into scripts within a Database project, and place under source code control. You can synchronise existing and deploy fresh databases from this project.
Visual Studio 2010 SQL Server Database Projects
An Overview of Database Build and Deployment
Visual Studio Database Guide
You can also use commercial tools such as those sold by RedGate.

Related

How to work in SQL Server as a team?

Me and my team are developing a SQL Server database. We want to work on different PCs, but with the same database. Is it possible that we can synchronise our work on each PC, or share our database while working somehow?
If possible how can Team Foundation server be used for that?
You can use SQL Server Database Tools (SSDT) to represent your database as a series of scripts. These scripts can then be added to source control. Git is by far the most popular source control system there is and Team Foundation Server and Visual Studio Team Services have great Git support.
Each developer will use Visual Studio (or VS Code) on their own machine to do their database work. When the developer wants to share their changes, they commit them to source control. Other developers can then update their local version of the code with the new changes. SSDT adds support for bringing your database and database project in sync.
Now that your code is in source control you can go a step further and add things like continuous integration builds and automated deployments with VSTS Build and Release Management. That way you can automatically test database changes and even run unit and integration tests before deploying to test and production environments.
The following Channel9 video gives an introduction to these tools: Database Continuous Integration and Deployment with Visual Studio SQL Server Data Tools in < 10 minutes
If you only care about schema changes (and not data changes), you can use visual studio's SQL Server projects, and a source control system, to help manage this. You can then use the Schema Compare tool to compare your project to the server, the server to your project, or server to server.
There are some tools from the likes of Redgate, etc, that allow this process to be automated. I've not used those, but they may be another option.

How to create/open DAC application in Visual Studio 2012?

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!

How do Visual Studio 2013 Database Projects work with TFS online and EntityFramework code first migrations

Fairly long title, but hopefully self-explanatory!
I'm starting a new project in Visual Studio 2013 using Entity Framework 5.0 with code first migrations.
I've connected my project to TFS Online using git - I'm interested in trying TFS Online as it offers source control management for 5 free projects (similar to BitBucket) but with strong Visual Studio integration.
I've not used Database projects in Visual Studio 2013 and I've found little information for how this all fits together.
What I'm trying to acheive is to create a simple Visual Studio solution with 2 projects - one an MVC .NET project and the other a database project. My goal is that code first migrations will make the neccessary changes to the sql scripts in the database project (which are managed under git source control). My web.config points to a local .mdb file as my database which is what is updated when I run update-database in EF which is what I feel is the problem.
How can I point EF to use my database project for code migration, and subsequently how can I automatically build my development database into a local .mdb file when debugging my solution?
Entity Framework Code First is a way to manage your SQL Schema. The single source of the truth lives in your code base. Migrations adds a way to move from one version of the schema to another. The SQL schema is a by-product of the build process.
SQL Server Database projects are also a way to manage your SQL Schema. The single source of the truth lives in your SQL Server Database project. You can use schema compare to generate scripts that move from one version to another.
Given that these technologies overlap in their intent and functionality, it doesn't really make sense to use them together. When you're using entity Framework Code First, leverage Migrations when you can (and when the features are sufficient for your situation).
When you're unable to use Migrations, you could use SQL Server Database projects to manage the schema and keep them in source control.
Note:
You should consider installing the SQL Server Data Tools as a replacement for the SQL Server Database projects should you want to use these. The data tools are a more advanced version of these projects, even if they might require Visual Studio 2012 to run for now. I suspect a version for Visual Studio 2013 will be available when Visual Studio 2013 hits RTM

Setup and Deployement in VB.Net having Sql Server Database in the Project

I have completed my Project in VB.Net and has published my project.
But i want to come out of these things
I have Sql Server Database in my project and i want my setup to add that database to sql server on installing my project.
I want my application to automatically detect sql server 2008 r2 and if it is not instaled i want it to install for me and then atach the database.
I dont want to add the database as a Attached database in my project.
i dont want to install crystal report in my application.
I have some unused refernces in my application in my project which i want to removed, i have tried the default visual studio remove unused references but still have some references like shockwave.dll log2net.dll etc.
The first step would be to switch to an MSI-based installer. This should allow you to resolve issues 3 and 5 (you control what the MSI includes). You can use a Visual Studio setup project, WiX or a commercial setup authoring tool.
For installing your database (issue 1), the best approach depends on how you use your database. Some installers simply copy the database files, others install it using custom actions and others execute SQL scripts. You should first determine how you want to install it and then ask a more specific question if you encounter problems.
To install SQL Server when it's not found (issue 2), you can use a prerequisite. This is done differently for each setup tool, so you first need to decide on a tool and then research how it supports prerequisites.
For issue 4, I'm not sure I know what to say. An MSI package will install what you include in it. If you don't add Crystal Reports in your package, then it won't be installed.
Visit
http://www.codeproject.com/Articles/10032/Deploy-SQL-Server-databases-easily-with-an-Install
Deploy SQL Server databases easily with an Installer class
Best regards!
Elias Sant Anna

How to build a specialized installer in VS2010?

I'm looking to build a specialized msi installer, preferably with VS2010 to do the following:
Be able to configure SQL server connection.
Pick the database to be used from the SQl server.
Create database table with specified credentials.
Assign a new DB user a set of permissions.
Also configure the IIS application.
I looked into a default installer project in VS2010 and it has nothing related to dealing with SQL server and IIS. Any idea how can I do all this?
Visual Studio setup projects do not offer support for SQL scripts and IIS. The best you can do is write some custom actions (using custom code) to handle this during install.
Commercial setup authoring tools offer the most control over SQL scripts and IIS elements. You can find a list here: http://en.wikipedia.org/wiki/List_of_installation_software
You can also try WiX. It has a steep learning curve, but it's free and gets the job done.

Resources