Creating Database Users

You can create user accounts for a certain database or create universal users with access to all databases within a subscription:

In this chapter:

Request Packet Structure

Response Packet Structure

Samples

 

Request Packet Structure

A request XML packet creating database user account for the database includes the add-db-user operation node:

<packet>
<database>
   <add-db-user>
   ...
   </add-db-user>
</database>
</packet>

 

The add-db-user node is presented by type DatabaseAddDBUserInputType (database_input.xsd), and its graphical representation is as follows:

CreateDbUserRPS

Remarks

You can add multiple users to database in a single packet. Add as many add-db-user operations to the packet as the number of different users you want to create. You can also add multiple users to multiple databases in a single packet.

<database>
   <add-default-user>
   ...
   </add-default-user>
   ...
   <add-default-user>
   ...
   </add-default-user>

</database>

Important: When creating request packets, put nodes and elements in the order they follow in the packet structure.

 

Response Packet Structure

The add-db-user node of the output XML packet is presented by type DatabaseAddDBUserOutputType (database_output.xsd) and structured as follows:

 

 

Samples

Creating a database user

This request packet creates user MyUser on the database with ID 55.

<packet>
<database>
   <add-db-user>
      <db-id>55</db-id>
      <login>MyUser</login>
      <password>hello</password>
      <role>writeOnly</role>
   </add-db-user>
</database>
</packet>

Reponse:

<packet>
<database>
   <add-db-user>
      <result>
         <status>ok</status>
         <id>132</id>
      </result>
   </add-db-user>
</database>
</packet>

 

If the database was not found, the response looks as follows:

<packet>
<database>
   <add-db-user>
      <result>
         <status>error</status>
         <errcode>1015</errcode>
         <errtext>Database not found</errtext>
      </result>
   </add-db-user>
</database>
</packet>

 

If the login name is already used by another user account on this database, the response looks as follows:

<packet>
<database>
   <add-db-user>
      <result>
         <status>error</status>
         <errcode>1007</errcode>
         <errtext>User already exists</errtext>
      </result>
   </add-db-user>
</database>
</packet> 
Creating multiple database users

This packet creates user MyUser on the databases with ID 55 and ID 57.

<packet>
<database>
   <add-db-user>
      <db-id>55</db-id>
      <login>MyUser</login>
      <password>hello</password>
   </add-db-user>

   <add-db-user>
      <db-id>55</db-id>
      <login>My2User</login>
      <password>123456</password>
   </add-db-user>

</database>
</packet> 

Reponse (if the first operation succeeded and the database with ID=57 was not found):

<packet>
<database>
   <add-db-user>
      <result>
         <status>ok</status>
         <id>132</id>
      </result>
   </add-db-user>

   <add-db-user>
      <result>
         <status>error</status>
         <errcode>1015</errcode>
         <errtext>Database not found</errtext>
      </result>
   </add-db-user>

</database>
</packet>