Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 17 » UltraLite - Database Management and Developer Guide » UltraLite database schemas » UltraLite users

Connection parameters for managing UltraLite users

You can use the UID and PWD connection parameters to create or authenticate users in an UltraLite database.

Note

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:

  • ULConnection.GrantConnectTo method [UltraLite C++]
  • ULConnection.RevokeConnectFrom method [UltraLite C++]
  • ULGrantConnectTo method [UltraLite Embedded SQL]
  • ULRevokeConnectFrom method [UltraLite Embedded SQL]
  • ULConnection.GrantConnectTo method [UltraLite.NET]
  • ULConnection.RevokeConnectFrom method [UltraLite.NET]

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.

Use connection parameters with UltraLite databases

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);
Use connection parameters with UltraLite databases on Android devices

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.