Connection.openFromString
gda.connection.Connection openFromString(string providerName, string cncString, string authString, gda.types.ConnectionOptions options)Opens a connection given a provider ID and a connection string. This allows applications to open connections without having to create a data source (DSN) in the configuration. The format of cnc_string is similar to PostgreSQL and MySQL connection strings. It is a semicolumn-separated series of <key>=<value> pairs, where each key and value are encoded as per RFC 1738, see [gda.global.rfc1738Encode] for more information.
The possible keys depend on the provider, the "gda-sql-5.0 -L" command can be used to list the actual keys for each installed database provider.
For example the connection string to open an SQLite connection to a database file named "my_data.db" in the current directory would be <constant>"DB_DIR=.;DB_NAME=my_data"</constant>.
The cnc_string string must have the following format: "[<provider>://][<username>[:<password>]@]<connection_params>" (if <username> and/or <password> are provided, and auth_string is null, then these username and passwords will be used, and if <provider> is provided and provider_name is null then this provider will be used). Note that if provided, <username>, <password> and <provider> must be encoded as per RFC 1738, see [gda.global.rfc1738Encode] for more information.
The auth_string must contain the authentication information for the server to accept the connection. It is a string containing semi-colon seperated named values, usually like "USERNAME=...;PASSWORD=..." where the ... are replaced by actual values. Note that each name and value must be encoded as per RFC 1738, see [gda.global.rfc1738Encode] for more information.
The actual named parameters required depend on the provider being used, and that list is available as the <parameter>auth_params</parameter> member of the #GdaProviderInfo structure for each installed provider (use [gda.config.Config.getProviderInfo] to get it). Similarly to the format of the connection string, use the "gda-sql-5.0 -L" command to list the possible named parameters.
Additionally, it is possible to have the connection string respect the "<provider_name>://<real cnc string>" format, in which case the provider name and the real connection string will be extracted from that string (note that if provider_name is not null then it will still be used as the provider ID).\
This method may fail with a GDA_CONNECTION_ERROR domain error (see the #GdaConnectionError error codes) or a GDA_CONFIG_ERROR domain error (see the #GdaConfigError error codes).
Parameters
providerName | provider ID to connect to, or null |
cncString | connection string. |
authString | authentication string, or null |
options | options for the connection (see #GdaConnectionOptions). |