0

I am writing an application in C# (.NET 4.0) which has to integrate with another, much older application. Part of the requirement is to integrate with a much older program that uses Pervasive PSQL Version 9. I asked this question about accessing the database without having to install an ODBC DSN. Part of the answer (thanks very much) is that I need to create a database using DTO.

I've used COM interop to access the dto2.dll COM library, and have read the samples, but I am having problems creating the database. Here is a summary of the code I'm using.

var session = new DtoSession();
var result = session.Connect("localhost", "", "");
Assert.AreEqual(dtoResult.Dto_Success, result);

testDB = new DtoDatabase {
    Session = session,
    Name = "Test1",
    Ddfpath = @"C:\TEMP\DATA\DDF",
    DataPath = @"C:\TEMP\DATA",
};

result = session.Databases.Add(testDB);
Assert.AreEqual(dtoResult.Dto_Success, result);

No matter what values I use for the Name and paths, that final Assert always fails. The error code is Dto_errDuplicateName. If I do not include the Session property I get a different error code (7039).

Has anyone done this successfully? What am I doing wrong?

Community
  • 1
  • 1
John Jeffery
  • 990
  • 5
  • 19

1 Answers1

1

I believe you are missing the Flags property of the DtoDatabase object. I had the following code in my archive as an example of adding a database with DTO. This code was probably written when DTO was first released but it works and the only difference I can see is the Flags property.

DtoSession session = new DtoSession();
dtoResult result;
result = session.Connect("localhost", "","");
if (result != dtoResult.Dto_Success)
{
    Console.WriteLine("Error connecting. Error code: " + result.ToString());
    return;
}
DtoDatabase testDB = new DtoDatabase();
testDB.Name = "Test1";
testDB.DataPath = @"C:\DATA";
testDB.DdfPath = @"C:\DATA";
testDB.Flags = dtoDbFlags.dtoDbFlagNotApplicable;
result = session.Databases.Add(testDB);
if (result != dtoResult.Dto_Success)
{
    Console.WriteLine("Error Adding. Error code: " + result.ToString());
    return;
}
Console.WriteLine("DB Added.");
mirtheil
  • 8,952
  • 1
  • 30
  • 29
  • Thanks for your reply. I probably should have mentioned that I have tried a number of different flag values. If you don't specify the flag value (like in my code) it defaults to dtoDbFlagNotApplicable. I have also tried dtoDbFlagBound, dtoDbFlagCreateDDF, and dtoDbFlagDefault. All combinations give me the same error result. Your answer is useful, however, because your working code tells me that I am on the right track. I'm going to install PSQL on a clean machine and try my code there -- I might have some sort of configuration problem. – John Jeffery Jan 25 '13 at 00:05