Get a list of Pervasive / Actian PSQL databases using C# and DTO

Recently a question came up on how to get a list of all of the database names on a Pervasive / Actian PSQL server from C#. The short answer is to use the DtoDatabase object within the Distributed Tuning Object (DTO) COM object. A reference to the DTO Library will need to be added for this code to work.
This sample is a simple console application that takes three paramaters (ServerName, UserName, Password).
Here’s the code sample that shows how to get the list:

using System;
using DTOLib;

namespace dtoTest
	class Class1
		static void Main(string[] args)
			string compName = null;
			string userName = null;
			string password = null;
			DTOLib.dtoResult result;
			if (args.LongLength < 1)
				Console.WriteLine("Invalid options.\n");
			if (args.LongLength == 3)
				compName = args[0].ToString();
				userName = args[1].ToString();
				password = args[2].ToString();
			Console.WriteLine("List Pervasive Database using DTO and C#");
			DtoSession mDtoSession = new DTOLib.DtoSession();
				result = mDtoSession.Connect(compName, userName, password);
				if (result != 0)
					Console.WriteLine("Error connecting to server.  Error code:");
					Console.WriteLine("Connected to " + mDtoSession.ServerName);
					DtoDatabase mDtoDatabase = new DTOLib.DtoDatabaseClass();
					int dbnCount = mDtoSession.DSNs.Count;
					Console.WriteLine("Found " + dbnCount.ToString() + " DBNs");
					for (int iCount = 1; iCount <= dbnCount; iCount++)
						Console.WriteLine("DBN " + iCount.ToString() + ": ");
						mDtoDatabase = mDtoSession.Databases[iCount];
						Console.WriteLine("Name: " + mDtoDatabase.Name);
						Console.WriteLine("DDF Path: " + mDtoDatabase.DdfPath.ToString());
						Console.WriteLine("Data Path: " + mDtoDatabase.DataPath.ToString());
						Console.WriteLine("Flags: " + mDtoDatabase.Flags.ToString());

					result = mDtoSession.Disconnect();
			catch (Exception e1)

2 thoughts on “Get a list of Pervasive / Actian PSQL databases using C# and DTO

  1. I would like to try this. But what is the actual name of that com object? I see Pervasive Distributed Tuning Library 1.0 and 2.0 Is that what to use?

  2. You can use either DTO library. The DtoDatabase collections are in both versions. If you are going to target multiple versions of the Pervasive Engine, you might want to use the 1.0 version as it supports older engines.

Leave a Reply

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