Create Pervasive Database using Distributed Tuning Objects (DTO)

家住魔仙堡 提交于 2019-12-25 06:49:08

问题


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?


回答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.");


来源:https://stackoverflow.com/questions/14496587/create-pervasive-database-using-distributed-tuning-objects-dto

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!