You can use the UID and PWD connection parameters to create or authenticate users in an UltraLite database.
As an alternative to connection parameters, you can use the following UltraLite API methods in your application to grant or revoke user access to an UltraLite database:
Grant and revoke methods are not available in the UltraLiteJ API. For Android devices, set the UID and PWD connection parameters using the ConfigPersistent.setConnectionString method.
For most UltraLite APIs, the createDatabase method of a DatabaseManager object can be used to create a new UltraLite database with the specified connection and creation parameters.
The following example illustrates how to create a default user for a new UltraLite database by passing the UID and PWD parameters to the CreateDatabase method in the UltraLite C++ API:
ULConnection * conn; ULError ulerr; ULDatabaseManager::CreateDatabase("dbf=sample.udb;uid=default-name;pwd=default-password", &ulerr);
The following example illustrates how to authenticate a user in an existing UltraLite database by passing the UID and PWD parameters to the OpenConnection method in the UltraLite C++ API:
ULConnection * conn; ULError ulerr; ULDatabaseManager::OpenConnection("dbf=sample.udb;uid=test-name;pwd=test-password", &ulerr);
For the UltraLiteJ API, you use the setConnectionString method of a Configuration object in the UltraLiteJ API to create or authenticate users.
The following example illustrates how to create a default user for a new UltraLite database by passing the UID and PWD parameters to the createDatabase method in the UltraLiteJ API:
ConfigFile config = DatabaseManager.createConfigurationFileAndroid("DBname.udb", getApplicationContext()); config.setConnectionString("uid=default-name;pwd=default-password"); Connection conn = DatabaseManager.createDatabase(config);
The following example illustrates how to authenticate a user in an existing UltraLite database by passing the UID and PWD parameters and the connect method in the UltraLiteJ API:
ConfigFile config = DatabaseManager.createConfigurationFileAndroid("DBname.udb", getApplicationContext()); config.setConnectionString("uid=test-name;pwd=test-password"); Connection conn = DatabaseManager.connect(config);
As an alternative to the setConnectionString method, you can use the setPassword or setUserName methods to create or authenticate a user, respectively.