You are here:

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! Smile

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:

image

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

image

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

image

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:
SNAGHTML1a5d8f63 

 

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

SNAGHTML1a610986

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:

SNAGHTML1a63768f

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! Smile

In the meantime, what feature is on your Gibraltar Software Christmas List? Share your ideas with us on Facebook and you’ll have a chance to win a fantastic prize!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

clear formSubmit