SQL DB Deployment - sql

The scenario:
I have written a software application that includes an installer, that is to be used by Mr Layman to install the system on to a single computer.
The system is a simple C# winforms application with an SQL Express database. The target machine would be a standard installation of Windows XP with SQL Express and .NET 3.5 installed.
I am able to create the installer for the winforms app, that would check the version, create all the directories and copy over all the necessary executable's etc. I have also an SQL script that will create the database and populate it with the necessary data. However I do not know how to go about creating a stand alone installer for the database on the target machine.
I have an SQL script that will create the database etc, but how do I make the installer run this script? I've had a google and I don't really know what I'm looking for, can someone point me in the right direction please.
Thank you in advance.

Create a custom action in the installer project that will take your SQL script and run it against the database. Here's an MSDN link that covers the basics.

An installer which runs SQL scripts can be created in 2 ways:
The very hard way:
create an installation with custom dialogs which retrieve the SQL connection information
save that information somehow (in an MSI package you can use installer properties)
write a custom action which uses that information to connect to SQL Server and run your script
The easy way:
use a setup authoring tool which supports SQL scripts
If you want a free solution, I recommend WiX. It has a steep learning curve, but it does what you need.

Related

How to deploy vb.net project with SQL Server CE as database

I created a vb.net project and I used SQL Server Compact Edition as my database. Now I want to create an installer for it, for installing on different PCs.
Does it require to install Visual Studio on the client PC? How should I create installer which will include that database file?
Sorry for my bad English.
Please help.
Thank you in advance.
This msdn link shows how to do it:
https://msdn.microsoft.com/en-us/library/aa983326.aspx
There are 2 parts to it:
Deploy the database file. This can be done by setting the file to copy local always and updating your connection string to point to this.
Deploy the sqlserverce dll's. Follow the instructions in the msdn link which will copy the 7 dll's locally. This means you don't have to install sqlserverce on the individual pcs.

How do I make sure SQL Server 2005 Express or later is installed on the target machine? And how do I run an SQL query at the end of an install?

I'm updating a program for my company that requires the user to have SQL Server 2005 Express or later installed on to their computer. We already ship it with a copy of the SQL Server 2008 Express installer, but how do I get the launch conditions to check for any SQL Server of 2005 or later?
The reason I need to be sure that SQL is installed is that I'm trying to automate a process where we had the user create a database and give that database permissions for certain users. I have someone who can help me with creating the automation process, but he has never had to do the installation package for such a process.
I'm guessing that I would need to put a custom action to call the SQL file in the Commit phase of the Installer. Is that correct?
To reiterate my questions: How do I make sure SQL Server 2005 Express or later is installed on the target machine with Visual Studio Installer Deloyment? And how do I run an SQL query at the end of an install?
Thank you for any help you can give me.
You didn't mention what setup authoring tool you are using.
The general approach for checking SQL Server 2005 as a launch condition is this:
create a registry search for this entry:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\90\Tools\ClientSetup\CurrentVersion
use the search property as a custom launch condition
the search property value should be greater than or equal to "9.0" for the condition to be true
For example, if the search property is SQL_SERVER_2005_SEARCH, you can use this launch condition:
SQL_SERVER_2005_SEARCH >= "9.0"
Windows Installer doesn't support SQL scripts, so they are usually executed through custom actions. There is no predefined support for this, so you will most likely need to write the custom action code yourself.
Most commercial setup authoring tools have built-in support for both launch conditions and SQL scripts. Some free tools may also offer something for them.
May these help:
http://msdn.microsoft.com/en-us/library/bb264562(v=sql.90).aspx
http://community.flexerasoftware.com/showthread.php?t=155357

publishiing of vb.net application with setup procces

how can i keep the sqlserver install automatically when i install my project with attached my own database to sqlserver 2008 express after publish my project. what is the code i can write to in the setup project under vb.net to keep this happened thanks a lot
To get it to install Sql Server Express, just tick the appropriate box in the prerequisites screen as described here.
To attach your db look at this article for various ways of doing it: Detaching and Attaching Databases
I think the recommended way is to use CREATE DATABASE FOR ATTACH

Best practices or tools for installing a SQL Server database

Best practices or tools for installing a SQL Server database
I have a SQL Server database designed with the SQL Server GUI database editor/Visual Studio.
What is the best way to "install" that database on other systems. Said another way how should I ship this thing?
I know I can save the scripts and set the primary/foreign keys with T-SQL but I suspect their is something better. I guess you could have people restore from backup but that does not seem very professional.
What other choices are there and what are the pluses and minuses?
For it to look professional make a small setup program.
You currently have sql scripts that you use to create your db.
Make yourself a small xml file that contains the path to your scripts.
Create a small c# library that will connect to the db server, and run those scripts.
You can test this outside of the setup, in visual studio, then add it to the setup like this.
To do this from your setup all you have to do is put the xml file in a component so it is deployed,
And create a custom action in your setup, that will call your C# lib, read the xml and run the scripts on the sql server to create your db.
Also, from a setup program it's easy to set a registry key to identify the version of the your db that you just installed.
The minuses and pluses: It's a bit of work to start with, but with this you'll have all the ground work done to handle upgrades automatically later on, to do so, just add an upgradeScript section to your xml, an attribute called version for each upgrade script, and simply compare it against the version of the db you have save in the registry. The advantage is this way it can easily scale with your project.
My previous answer is mostly to keep full control on the deployment and upgrades.
I have searched for more built-in and streamlined solution that goes along with the DB designer mode you have used.
I found that in the version Studio 2005 Team Edition for Database Professionals of visual studio there might be deployment features.
Build and Deployment
You've seen that you can generate a
T-SQL update script manually via the
Schema Comparison tool. However, as
part of the build process, DB Pro
edition can generate a complete script
for deploying your database project.
This deployment script can do either a
complete build or an incremental
update. The build process can even
consolidate all of your pre- and
post-deployment scripts into one
complete deployment script. You can
deploy the script via the Build |
Deploy Selection command right from
within Visual Studio 2005. Under
project properties, you will find a
number of options to control and
adjust the build process. The Build
tab contains the core settings, such
as Target connection, Target database
name, and Block incremental deployment
if data loss might occur. You'll note
there is also a Build Events tab that
you can use to type pre- or post-build
event commands. DB Pro edition uses
MSBuild for its build process and
supports integration with Team Build
if you're using Team Foundation
Server.

Visual basic .net 2008 Deployment

Is it possible to make a setup and deployment project in VB.net 2008, every site i have looked at on google says to just select it from the project list. It isnt in the project list for me to select.
Are these types of projects not available in the express version?
How can I make an installer, other than using one of the setup and deployment projects? (I know there is a publish button, but that doesn't make a proper installer and installs to the appdata folder which is not what i want it to do)
Any help is appreciated
You would need to use another program, such as innosetup (http://www.jrsoftware.org/isinfo.php), to create a setup.exe. Microsoft has to give you some reason to purchase their software.
Express editions do not have these project types. They support ClickOnce only, per this chart:
http://msdn.microsoft.com/en-us/library/zcbsd3cz(VS.80).aspx
This carries over to the 2008 versions as well.
Edit - Added
See here for using ClickOnce from an Express edition:
http://blogs.msdn.com/vbteam/archive/2008/10/02/looking-for-setup-and-deployment-project-templates.aspx
You could use Inno Setup
It pretty much will do what you need to create an installer package. Oh yeah, and it's free.