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 { [STAThread] 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"); return; } 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(); try { result = mDtoSession.Connect(compName, userName, password); if (result != 0) { Console.WriteLine("Error connecting to server. Error code:"); } else { 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()); Console.WriteLine(""); } result = mDtoSession.Disconnect(); Console.ReadLine(); } } catch (Exception e1) { Console.WriteLine(e1.Message.ToString()); } } } }
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.