Visual Studio Setup and Deployment Project and .bat files???

Okay, Microsoft has a pretty slick method of deploying projects, especially with the 'prerequisites' settings.

However, I need to run an SQL script at the end of the installation to build a new database for SQLExpress.

Q. Is there any way to run a .bat or .sql within the VS2005 Setup Deployment project???
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

If you add an Installer.cs to your main project and override the Install and UnInstall methods
(Add the System.Configuration.Install to your project references)

using System;
using System.Configuration.Install;

namespace ExpertsExchange.Q_21804504
      /// <summary>
      /// Summary description for Installer.
      /// </summary>
      public class Installer : Installer
            public Installer()
                  // TODO: Add constructor logic here

            public override void Install(System.Collections.IDictionary stateSaver)
                  base.Install (stateSaver);
                  //Write your code to execute your sql script

            public override void Uninstall(System.Collections.IDictionary savedState)
                  base.Uninstall (savedState);
                  //Write your code to get rid of the Sql Script
As far as detail on how to run a script there is quite a long winded version here.

The above code however is the basis for what you need to do.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
kvnsdrAuthor Commented:
Interesting, but are we talking about the same thing.

I like the VS2005 .NET 2.0 Installer Project and it's use of 'Prerequisites' (much like Click-Once).

I'm not sure how the installer.cs can install the SQL scripts like Wise or InstallSheild do....

I need something that will simiulate a simple, no-hands-on end-user install.

So when the end-user double-clicks his desktop Icon, everything is installed with nothing for the end-user to do.

Sorry if I maybe missing your point.

I'm very interested and need additional explaination.....

The word 'Override' makes me think this installer.cs may compromise the VS Installer....

Help me understand.............

Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

What language are you developing in?

Override is what happens when you need to perform some extra functionality in a derived class that the base class doesn't provide. If you see the base.Install(etc) is the first call in my override which basically means do what you were going to do before I do what I want to do. All the normal install stuff happens before you do your custom stuff. And your custom stuff is to run a database script against the target db.

When the installer project is installing your software, it looks for any installation code that needs to be run in the projects it has just installed. The above code is one such instance. When the msi calls this code, the base installation stuff is done before your own extra installation requirements. These can be anything from creating a new web site, installing some other project or (in your case) executing a sql script to create the necessary database for your project.

This is what would be done in 2003. Its probably still the same in 2005 but I shall check....

If you are doing this in then we have to change the code slightly.

As far as simulating a no-hands-on install, thats what this does.

A question to you would be: What will you do if the end user already has a version of SQL on their machine that has security tightly configured? You must ask them for a secure method to communicate with the database or otherwise create a new instance.... if you create a new instance on some peoples machines by default, they may not be too happy.

Is this an internal business project or an external Joe Public project?

I shall return after checking the vs2005 install procedures. Someone will probably beat me to the answer however.


Yep, still the same.

the following is a more detailed version of what you are trying to do.
        public override void Install(System.Collections.IDictionary stateSaver)
            System.Diagnostics.Process process = new System.Diagnostics.Process();
            process.StartInfo.FileName = "oSql.exe";
            process.StartInfo.Arguments = "-E -S ServerName\InstanceName -i YourSqlScript.sql";
            //If you want to do it Syncronously
            //Otherwise if you want to do it Asynchronously
            //process.Exited +=new EventHandler(process_Exited);
            if (!process.Start())
                //Something went wrong so you may want to roll back the installation
                //Unless you are happy for the user to do there own fixes
            stateSaver.Add("ScriptInstall", true);
kvnsdrAuthor Commented:
Okay, I've downloaded and inspected the project from the link above:

I understand they added an 'Installer.cs' into thier application project.

It's like an installer wrapped within another installer.

Q. What 'fires' the installer to do it's job?
kvnsdrAuthor Commented:
Here's another link I found concerning the Installer class!

Thank you all..............

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.