# JSConnectionDefinition

## Overview

The `JSConnectionDefinition` provides a mechanism for creating and managing client-specific database server connections at runtime in the Servoy environment. It is accessed through `datasources.db.myserver.defineClientConnection()` and allows configuration of database connections tailored to the current client session.

This class enables setting properties such as `username` and `password` for authentication and allows additional connection properties to be defined as key-value pairs. These configurations can be dynamically registered to a server, ensuring that all subsequent connections to the database for that client use the specified settings.

Key functionalities include the ability to retrieve or modify connection details like the username, password, and custom properties. The connection definition can be registered with the server using the `create` method, or unregistered and destroyed with the `destroy` method, ensuring flexibility in managing runtime database interactions.

## Methods Summarized

| Type                                                                                          | Name                                              | Summary                                                                                                                                       |
| --------------------------------------------------------------------------------------------- | ------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
| [JSConnectionDefinition](/reference/servoycore/dev-api/datasources/jsconnectiondefinition.md) | [create()](#create)                               | Registers this JSConnectionDefinition to the server with the current configuration.                                                           |
| void                                                                                          | [destroy()](#destroy)                             | Destoyes this JSConnectonDefintion, this unregisteres this on the server so it will not use this configuration anymore to create connections. |
| [String](/reference/servoycore/dev-api/js-lib/string.md)                                      | [password()](#password)                           | returns the password that was set by password(string)                                                                                         |
| [JSConnectionDefinition](/reference/servoycore/dev-api/datasources/jsconnectiondefinition.md) | [password(password)](#password-password)          | Sets the password to use for this client connection.                                                                                          |
| [JSConnectionDefinition](/reference/servoycore/dev-api/datasources/jsconnectiondefinition.md) | [setProperty(key, value)](#setproperty-key-value) | Set a key value pair that is used as a connection property for this connection definition                                                     |
| [String](/reference/servoycore/dev-api/js-lib/string.md)                                      | [username()](#username)                           | returns the username that was set by username(string)                                                                                         |
| [JSConnectionDefinition](/reference/servoycore/dev-api/datasources/jsconnectiondefinition.md) | [username(username)](#username-username)          | Sets the username to use for this client connection.                                                                                          |

## Methods Detailed

### create()

Registers this JSConnectionDefinition to the server with the current configuration.\
After this call all connections to that database will use the configuration of this definition.

**Returns:** [JSConnectionDefinition](/reference/servoycore/dev-api/datasources/jsconnectiondefinition.md) The this if it could be created, this will return null if there was a creating this definition (check logs)

### destroy()

Destoyes this JSConnectonDefintion, this unregisteres this on the server so it will not use this configuration anymore to create connections.

**Returns:** void

### password()

returns the password that was set by password(string)

**Returns:** [String](/reference/servoycore/dev-api/js-lib/string.md) the password for this connection.

### password(password)

Sets the password to use for this client connection.

**Parameters**

* [String](/reference/servoycore/dev-api/js-lib/string.md) **password** ;

**Returns:** [JSConnectionDefinition](/reference/servoycore/dev-api/datasources/jsconnectiondefinition.md) this

### setProperty(key, value)

Set a key value pair that is used as a connection property for this connection definition

**Parameters**

* [String](/reference/servoycore/dev-api/js-lib/string.md) **key** The propertie key
* [String](/reference/servoycore/dev-api/js-lib/string.md) **value** The property value

**Returns:** [JSConnectionDefinition](/reference/servoycore/dev-api/datasources/jsconnectiondefinition.md) this

### username()

returns the username that was set by username(string)

**Returns:** [String](/reference/servoycore/dev-api/js-lib/string.md) the username for this connection.

### username(username)

Sets the username to use for this client connection.

**Parameters**

* [String](/reference/servoycore/dev-api/js-lib/string.md) **username** ;

**Returns:** [JSConnectionDefinition](/reference/servoycore/dev-api/datasources/jsconnectiondefinition.md) this

***


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.servoy.com/reference/servoycore/dev-api/datasources/jsconnectiondefinition.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
