HOWTO for common tasks: GNOME Data Access 5 manual

## HOWTO for common tasks

This section is a list of small HOWTOs to get started quickly for some specific tasks, without the need to read all the documentation: quickly get to the code and read the corresponding documentation for further details.

## Open a connection

Opening a connection to a database creates a GdaConnection object which is required to execute commands. The connections' parameters (which are specific to each type of database) can be either specified when opening the connection, or be used to define a data source (DSN) and the DSN name is then specified to open the connection.

For example, opening a connection to a PostgreSQL database named "mydb" one could use the following code:

    GdaConnection *connection;
    connection = gda_connection_open_from_string ("PostgreSQL", "DB_NAME=mydb",
                                                  "USERNAME=martin;PASSWORD=luther",
                                                  GDA_CONNECTION_OPTIONS_READ_ONLY, NULL);
    if (!connection)
        g_print ("CONNECTION FAILED\n");
    else {
        /* use the opened connection */

        /* close the connection (assuming it's not used by another object) */
        g_object_unref (connection);
    }