Features:
The top-level object of the NDO UCX component. Used for retrieving information about text windows.
An open connection to a data source.
Acts as an entry point to other NDO objects.
Performs commit or aborts and starts a new transaction automatically.
Object.Attributes = Value
Long.
Read/Write.
For a Connection object, the Attributes property is read/write, and its value can be the sum of any one or more of these XactAttributeEnum values. By default the attributes is set to zero.
Contains the information used to establish a connection to a data source.
object.ConnectionString
String.
Read/write.
The format of the connection string is similar to an ODBC connection string. For example: DBType=0;Database=MyServer-TCP.World;UID=Scott;PWD=Tiger
The valid DBTypes are:
4 for MySQL database
1 for B2System SQLIntegrator database
0 for Oracle 8 database
A valid database name that corresponds to the database type specified by DBType
A valid user ID for the database.
A valid password for the user ID and database.
CN.Open ("DBTYPE=4;DATABASE=test", "root","")
Add the string Host = IP Address at the end of the connection string, where ip address represents the ip address of the server hosting the remote database.
For example the connection string to access the remote database present in the server 123.45.678.910 is:
CN.Open ("DBTYPE=4;DATABASE=test;HOST=123.45.678.910", "root","")
Modify the active connection state. For example to access the MySQL database, the DBTYPE should be set to 4.
CN.ActiveConnection ="DBTYPE=4;DATABASE=test;UID=root;PWD="
Add the string Host = IP Address at the end of the connection string, where ip address represents the ip address of the server hosting the remote database.
For example the connection string to access the remote database present in the server 123.45.678.910 is:
CN.ActiveConenction ("DBTYPE=4;DATABASE=test;HOST=123.45.678.910", "root","")
See Sample to Access the MySQL Database Using the Connection Object or Sample to Access the Oracle Database Using the Connection Object.
Returns the default database for a Connection object.
object.DefaultDatabase
String. Evaluates to the name of a database available from the provider.
Read/write.
Describes the current state of an object.
object.State
Constant.
Read-only.
This property returns one of the following constants:
SeeSample to Access the MySQL Database Using the Connection Object or Sample to Access the Oracle Database Using the Connection Object.
Returns the data connector component’s version number.
object.Version
String.
Read-only.
Begins a new transaction.
object.BeginTrans()
None.
None.
To specify a different isolation level, use the Execute methods (of the Command, Connection, and Database objects) to begin the transaction (B2Systems SQLIntegrator only.).
The default isolation level that is enforced by this method is READ COMMITTED. This allows users to change or add records while these records are being read by other users.
Consider the following scenario:
Alan reads a record.
Beth modifies or deletes the record in a transaction, then commits the transaction.
Alan re-reads the record and finds that it has been changed or deleted. Alan then reads a set of records that satisfy a specific WHERE clause.
Beth inserts a record that satisfies the same WHERE clause.
When Alan repeats the first query, the set of records satisfying the WHERE clause has changed.
See Sample to Access the MySQL Database Using the Connection Object or Sample to Access the Oracle Database Using the Connection Object.
Closes a Connection object and any active Recordset objects associated with the Connection.
object.Close()
None.
None.
Using this method to close a Connection object also closes any active Recordset objects associated with the connection.
A Command object associated with the Connection object you are closing will persist, but it will no longer be associated with a Connection object. That is, its ActiveConnection property will be set to Nothing. In addition, the Command object’s Parameters collection will be cleared of any provider-defined parameters.
See Sample to Access the MySQL Database Using the Connection Object or Sample to Access the Oracle Database Using the Connection Object.
Saves any changes and ends the current transaction.
object.CommitTrans()
None.
None.
See Sample to Access the MySQL Database Using the Connection Object or Sample to Access the Oracle Database Using the Connection Object.
Executes the specified query, SQL statement, stored procedure, or provider-specific text.
object.Execute(
CommandText As String,
RecordsAffected As Long)
A String containing the SQL statement, table name, stored procedure, or provider-specific text to execute. Currently supports only SQL statements.
Optional. A Long variable to which the provider returns the number of records that the operation affected.
Returns a Recordset object reference if the command text specifies a row returning query; otherwise, it returns Nothing.
See Sample to Access the MySQL Database Using the Connection Object or Sample to Access the Oracle Database Using the Connection Object.
Opens a connection to a data source.
object.Open(
ConnectionString As String,
UserID As String,
Password As String)
A String containing connection information.
A String containing a user name to use when establishing the connection.
A String containing a password to use when establishing the connection.
Returns a Recordset object reference if the command text specifies a row returning query else returns NULL.
The format of the connection string is similar to an ODBC connection string. For example: DBType=0;Database=MyServer-TCP.World;UID=Scott;PWD=Tiger
The valid DBTypes are:
4 for MySQL database
1 for B2System SQLIntegrator database
0 for Oracle 8 database
A valid database name that corresponds to the database type specified by DBType
A valid user ID for the database.
A valid password for the user ID and database.
CN.Open ("DBTYPE=4;DATABASE=test", "root","")
Add the string Host = IP Address at the end of the connection string, where ip address represents the ip address of the server hosting the remote database.
For example the connection string to access the remote database present in the server 123.45.678.910 is:
CN.Open ("DBTYPE=4;DATABASE=test;HOST=123.45.678.910", "root","")
Modify the active connection state. For example to access the MySQL database, the DBTYPE should be set to 4.
CN.ActiveConnection ="DBTYPE=4;DATABASE=test;UID=root;PWD="
Add the string Host = IP Addressat the end of the connection string, where ip address represents the ip address of the server hosting the remote database.
For example the connection string to access the remote database present in the server 123.45.678.910 is:
CN.ActiveConenction ("DBTYPE=4;DATABASE=test;HOST=123.45.678.910", "root","")
See Sample to Access the MySQL Database Using the Connection Object or Sample to Access the Oracle Database Using the Connection Object
This sample script retrieves the details stored in the table emp present in the database mysql2 hosted by the server 123.45.678.910a.
Option VBA
’On Error Resume Next
Set CN = CreateObject("UCX:NDODB.CONNECTION")
CN.Open ("DBTYPE=4;DATABASE=mysql2;HOST=123.45.678.910",
"root","")
Set RS = CN.Execute("select * from mysql2",lrec)
DisplayRS (RS)
RS.Close
’ Subroutine to display the details of a record set.
Sub DisplayRS(RS As Object)
Dim FLDS As Object
Dim FLD As Object
Dim RecValue As String
Dim FldCount As Long
Set FLDS = RS.FieldsRecValue = ""
For FldCount = 1 To FLDS.Count
Set FLD = FLDS.Item(FldCount)
RecValue = RecValue & " " & CStr(FLD.Name)
Next
Print RecValue
PrintLine (60)
Print " RS COUNT"
Print RS.RecordCount
Do
RecValue = ""
Set FLDS = RS.Fields
For FldCount = 1 To FLDS.Count
Set FLD = FLDS.Item(FldCount)
RecValue = RecValue & " " & CStr(FLD.Value)
Next
Print RecValue
RS.MoveNext
Print RS.EOF
Loop While Not RS.EOF
End Sub
’Subroutine to print a line
Sub PrintLine(Number)
For PrintCount = 1 To Number
Line = Line & "-"
Next
Print Line
End Sub
This sample script retrieves details about all the employees stored in the EMP table of Oracle* database.
The sample does the following:
’Create a connection object and open a connection to Oracle database.
Option VBA
On Error Resume Next
Set CN = CreateObject("UCX:NDODB.CONNECTION")
CN.BeginTrans
CN.Open ("DBTYPE=0;DATABASE=ORANW81.WORLD", "scott","tiger")
’Execute the SQL query to retrieve the employee details
Set RS = CN.Execute("Select * from emp", lRec)
If Err <> 0 Then
GoTo errorhandler
End If
DisplayRS (RS)’ Display the properties of the connection object
’
PrintLine(50)
Print "RecordSet ActiveConnection"
Print RS.ActiveConnection
RS.ClosePrintLine(50)
Print "Connection String "
Print CN.ConnectionString
PrintLine(50)
Print "Connection State "
Print CN.State
PrintLine(50)
Print "Connection version "
Print CN.Version
PrintLine(50)
Print "Default DataBase "
Print CN.DefaultDatabase
PrintLine(50)
Print "Connection Attributes "
Print CN.Attributes
PrintLine(50)
CN.Close
’ Subroutine to display the details of a record set.
’
Sub DisplayRS(RS As Object)
Dim FLDS As Object
Dim FLD As Object
Dim RecValue As String
Dim FldCount As Long
Set FLDS = RS.Fields
RecValue = ""
For FldCount = 1 To FLDS.Count
Set FLD = FLDS.Item(FldCount)
RecValue = RecValue & " " & CStr(FLD.Name)
Next
Print RecValue
PrintLine (60)
Do
RecValue = ""
For FldCount = 1 To FLDS.Count
Set FLD = FLDS.Item(FldCount)
RecValue = RecValue & " " & CStr(FLD.Value)
Next
Print RecValue
RS.MoveNext
Loop While Not RS.EOF
End Sub’Subroutine to print a line
’
Sub PrintLine(Number)
For PrintCount = 1 To Number
Line = Line & "-"
Next
Print Line
End Sub