" *****************************************************************************************************
* connect.txt
*
This examples shows how to open a connection and use connect to
*   connect to a Data Source
*
******************************************************************************************************"

|connection1  aTextDisplay connectString dsn userId password|

aTextDisplay := TextWindow  windowLabeled: 'ODBC Interface - Using Connect '
                           frame: (0 @ 0 corner: 1000 @ 1000).
aTextDisplay cr.



" *** Open the connection ****"

connection1 := OdbcConnection open.
connection1 hasError
    ifTrue:
    [    aTextDisplay nextPutAll: connection1 getMessage; cr
    ].



" *** Connect ***
We only need DSN, Uid and Password to connect ... "

dsn := Prompter prompt: 'Please Enter Data Source Name:' default: ''.
userId := Prompter prompt: 'Please Enter User ID:' default: ''.
password := Prompter prompt: 'Please Enter password:' default: ''.

connection1 connect: dsn userId: userId password: password.

connection1 hasError
    ifTrue:
    [    aTextDisplay nextPutAll: connection1 getMessage; cr
    ].



aTextDisplay cr
                     ; nextPutAll: 'connection using connect completed'
                    ;cr.


" *** disconnect *** "
connection1 disconnect.
connection1 hasError
    ifTrue:
    [    aTextDisplay nextPutAll: connection1 getMessage; cr
    ].


" *** free the connection *** "

connection1 free.
connection1 hasError
    ifTrue:
    [    aTextDisplay nextPutAll: connection1 getMessage; cr
    ].


aTextDisplay nextPutAll: '*** finished executing ***'.
