VistaDB: Deploying Your Database

Hello! This feature is the tasty treat behind door number 3 of our Gibraltar Software Advent Calendar and shows you how to deploy your VistaDB solution. By far the easiest way to get a VistaDB deployment done is via an XCopy deployment. Of course, despite the name, you don’t actually have to use XCopy to get the job done!

Okay, let’s go ahead and look at an example. First, let’s create a simple example application, let’s make it a C# console application:

2012-12-03-1

Next, open VistaDB Data Builder and create a simple database just holding Fullname and age:

2012-12-03-2

Now, pull the database into your project and set it’s properties to “Copy if newer”:

2012-12-03-3

Next, write some code to interact with the database:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VistaDB.Provider;

namespace XCopyDeploymentExample {
    class Program {
        static void Main(string[] args) {
            Insert();
            Update();
            Delete();
        }

        static private void Insert() { 
            using(VistaDBConnection conn = GetConnection()) {
                conn.Open();
                using (VistaDBCommand cmd = new VistaDBCommand()) {
                    cmd.Connection = conn;
                    cmd.CommandText = "INSERT INTO Person (Fullname, age) " +
                        "VALUES ('Gary', 42)";
                    int rowsAffected = cmd.ExecuteNonQuery();
                    Console.WriteLine("{0} row(s) inserted.", rowsAffected);
                }
                conn.Close();
            }
        }

        static private void Update() {
            using (VistaDBConnection conn = GetConnection()) {
                conn.Open();
                using (VistaDBCommand cmd = new VistaDBCommand()) {
                    cmd.Connection = conn;
                    cmd.CommandText = "UPDATE Person SET Age = 24 " +
                        "WHERE FullName = 'Gary'";
                    int rowsAffected = cmd.ExecuteNonQuery();
                    Console.WriteLine("{0} row(s) updated.", rowsAffected);
                }
                conn.Close();
            }
        }

        static private void Delete() {
            using (VistaDBConnection conn = GetConnection()) {
                conn.Open();
                using (VistaDBCommand cmd = new VistaDBCommand()) {
                    cmd.Connection = conn;
                    cmd.CommandText = "DELETE FROM Person";
                    int rowsAffected = cmd.ExecuteNonQuery();
                    Console.WriteLine("{0} row(s) deleted.", rowsAffected);
                }
                conn.Close();
            }
        }

        static VistaDBConnection GetConnection() {
            return new VistaDBConnection("Data Source = Data.vdb4");
        }
    }
}

And finally test it locally:

2012-12-03-4

Now, simply drag the executable file, the VistaDB DLL and the database to the target location:

2012-12-03-5

Note that, at the time of this blog post, the VistaDB.4.dll file can be found, by default, at:

C:\Program Files (x86)\VistaDB 4.3.3\Runtimes

Now simply run your application in the target location:

2012-12-03-6

There you go, it’s as simple as that! Do you have a super simple deploy mechanism for VistaDB? If so, when not share it with us all by posting in the comments.

Well that’s all for this post, until next time, happy coding!

The No Hassle Embedded Database for .NET

License your team and deploy worldwide, royalty-free, starting at $1,595/site