Switch to: V10V9V8V7V6V5

Lesson 2 - Remote Database

Before you begin, download and install Valentina Server. It does not matter if it is the same operating system or not with the one upon which you will do this tutorial.

This lesson demonstrates how to change the code from the Lesson 1 tutorial to work with a remote copy of Valentina Server. The Lesson 1 tutorial demonstrated how to work with a local database.

Step 2: Init Client

#include <VSDK/VSDK2.h>
 
using namespace FBL;
 
int main()
{
    ValentinaInitC();
 
    // ...
 
    ValentinaShutDownC();
}

We need to use Valentina_InitC() and Valentina_ShutDownC() methods, because we want to use now VCLIENT.DLL, but not VKERNEL.DLL

Step 3: Make Connection

int main()
{
    ValentinaInitC();
 
    // Make Connection object:
    I_Connection_Ptr pConnection = CreateConnection( "localhost", "sa", "sa", "UTF-8" );
    pConnection->Open();
 
 
    // Make CPP object for DB:
    I_SqlDatabase_Ptr pSqlDb = CreateSqlDatabase( pConnection );
    I_Database_Ptr pDb = pSqlDb->get_BaseDatabase();
 
 
    // Create DB on VSERVER with name:
    I_Location_Ptr pDbLocation = CreateRawLocation( "db1.vdb" );
    pDb->put_Location( pDbLocation );
    pDb->Create();
 
 
    // WORK WITH DB:
    CreateSchema( pSqlDb );
    InsertRecords( pSqlDb );
    SelectRecords( pSqlDb );
 
 
    // Close all:
    pDb->Close(); 
    pConnection->Close();
    ValentinaShutDownC();
}
  • You need to create a Connection object and then open it. To create a connection object, you specify parameters of VSERVER: IP, login, password, connection encoding, etc.
  • This connection object you should pass into factory CreateSqlDatabase().
  • Location is created with the help of the CreateRawLocation() method, which accepts always only database name, not a path on disk. This is because VSERVER manages databases by their names only.