SQL927: Using SQL Anywhere Studio: Alex Reif Product Manager August 15-19, 2004
SQL927: Using SQL Anywhere Studio: Alex Reif Product Manager August 15-19, 2004
with .NET
Alex Reif
Product Manager
[email protected]
August 15-19, 2004
Agenda
Introduction to .NET
ASA and ADO.NET
ASA and Web Services
UltraLite.NET
The Enterprise. Unwired.
The Enterprise. Unwired.
Sybase Workspace
Agenda
Introduction to .NET
ASA and ADO.NET
ASA and Web Services
UltraLite.NET
.NET: Definition
http://www.microsoft.com/net/basics/faq.asp
.NET Framework
Namespace
“A logical naming scheme for grouping related types”
Analogous to Java packages
iAnywhere.Data.AsaClient.AsaConnection
iAnywhere.Data.AsaClient is the namespace
Assembly
“A collection of one or more files that are versioned and deployed as a
unit”
DLLs in .NET-land
Unlike DLLs, .NET assemblies also include version control/security
information
GAC (Global Assembly Cache)
“A machine-wide code cache that stores assemblies specifically
installed to be shared by many applications on the computer”
What is ADO.NET?
Introduction to .NET
ASA and ADO.NET
ASA and Web Services
UltraLite.NET
ASA Interfaces
ODBC
ESQL
OLEDB
Open Client
JDBC
Perl
PHP
…
ADO.NET
ADO.NET Data Providers For ASA
OLEDB
ODBC
AsaClient
ASA
ASA Data Provider
DGEmployees.DataSource = ds
DGEmployees.DataMember = "Employees"
Using the ASA Data Provider
using iAnywhere.Data.AsaClient;
ds = new DataSet();
dataGrid1.DataSource = ds;
dataGrid1.DataMember = "product";
}
ASA ADO.NET Data Provider
Classes Enumerations
AsaConnection AsaDbType
AsaError
AsaException Delegates
AsaInfoMessageEventHandler
AsaCommand
AsaRowUpdatedEventHandler
AsaParameter
AsaDataReader
AsaRowUpdatingEventHandler
AsaDataAdapter
AsaCommandBuilder
AsaErrorCollection
AsaInfoMessageEventArgs
AsaParameterCollection
AsaPermission
AsaPermissionAttribute
AsaRowUpdatedEventArgs
AsaRowUpdatingEventArgs
AsaTransaction
ADO.NET Application Tasks
Connecting
Error handling
Executing SQL
Retrieving data
Transactions
Disconnected result sets
Connecting
AsaConnection
Represents a connection to an ASA database
Uses normal ASA connection strings
Optional use of event handlers (InfoMessage, StateChange)
Connection Example
using iAnywhere.Data.AsaClient;
myConn.ConnectionString =
"Data Source=ASA 9.0 Sample;UID=DBA;PWD=SQL";
myConn.Open();
Connection Pooling
myConn.ConnectionString =
“POOLING=FALSE;Data Source=ASA 9.0 Sample;UID=DBA;PWD=SQL";
Error Handling
AsaException
Thrown by a failed statement (try/catch)
Message parameter contains error message
Errors property is a collection of ASAError objects
AsaError
More detailed ASA-specific error information
Message, NativeError, Source, SqlState
Errors and Exceptions Example
try {
myConn = new AsaConnection(
"Data Source=ASA 9.0 Sample;UID=DBA;PWD=SQL” );
myConn.Open();
} catch( AsaException ex ) {
MessageBox.Show(
ex.Errors[0].Source + " : " +
ex.Errors[0].Message + " (" +
ex.Errors[0].NativeError.ToString() + ")",
"Failed to connect" );
}
Executing SQL
AsaCommand
Represents a SQL statement or stored procedure that is executed
against an Adaptive Server Anywhere database
Parameter property is a collection AsaParameter objects
Stored procedures
Use the name of the procedure as the statement (no “call” or “exec”)
Set the CommandType property to StoredProcedure
AsaCommand Example
AsaConnection myConn;
AsaCommand myCmd;
int num_depts;
AsaDataReader
Read-only, forward-only result set from a query or stored procedure
(rows are fetched as needed)
GetXXX methods to get column value as specific data types
Read method moves to next row
AsaDataAdapter
Used to fill a DataSet; fetches all rows and closes cursor
More on this later…
DataReader Example
myConn.Open();
reader = cmd.ExecuteReader();
while( reader.Read() ) {
int dept_id = reader.GetInt32(0);
string dept_name = reader.GetString(1);
MessageBox.Show( "dept_id: " + dept_id +
"\ndept_name: " + dept_name );
}
reader.Close();
DataReader Example – BLOBs
byte[] bitmap;
long len;
if( reader.Read() )
{
// get the length of the BLOB by passing a NULL buffer
len = reader.GetBytes(0, 0, null, 0, 0);
bitmap = new byte[len];
AsaTransaction
Represents a SQL transaction
Returned by ASAConnection.BeginTransaction()
Commit, Rollback methods
IsolationLevel property
myTran = myConn.BeginTransaction();
myCmd = new AsaCommmand(
“call sp_update_some_data()”, myConn, myTran );
…
myTran.Commit();
Disconnected Result Sets
AsaDataAdapter
Represents a set of commands and a database connection used to fill
a DataSet and to update a database
Fill method fetches all rows and closes cursor
Update method applies changes to DataSet to database (beware of
ConcurrencyException!)
SelectCommand, InsertCommand, UpdateCommand,
DeleteCommand properties
AsaCommandBuilder
Attached to an AsaDataAdapter
Given a SELECT statement, generates corresponding
INSERT/UPDATE/DELETE statements
DataAdapter Example
AsaDataAdapter da;
AsaCommandBuilder cb;
DataSet ds;
ds = new DataSet();
da.Fill(ds, "product");
dataGrid1.DataSource = ds;
dataGrid1.DataMember = "product";
}
iAnywhere.Data.AsaClient.dll dbdata9.dll
Your
Application
ASA
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity
name="iAnywhere.Data.AsaClient"
publicKeyToken="f222fc4333e0d400"
/>
<bindingRedirect
oldVersion="9.0.1.0-1883"
newVersion="9.0.1.1883"
/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Application Deployment: Win32
iAnywhere.Data.AsaClient.dll
Register with gacutil.exe (shipped with .NET)
dbdata9.dll
No registration required
Application Deployment: Windows CE
Emulator
Run ASA on desktop, not emulator
Deploying ASA to Pocket PC 2002 (or higher) Emulator
• Create x86 CAB file, map drive from device to desktop
Device
Connecting to ASA on device from desktop using ActiveSync:
http://www.ianywhere.com/developer/technotes/activesync_asa.html
Agenda
Introduction to .NET
ASA and ADO.NET
ASA and Web Services
UltraLite.NET
ASA: Built-in HTTP Server
CREATE SERVICE service-name TYPE service-type-
string [ attributes ] [ AS statement ]
attributes:
[ AUTHORIZATION { ON | OFF } ]
[ SECURE { ON | OFF } ]
[ USER { user-name | NULL } ]
[ URL [ PATH ] { ON | OFF | ELEMENTS } ]
[ USING { SOAP-prefix | NULL } ]
service-type-string:
{ 'RAW' | 'HTML' | 'XML' | 'SOAP' | 'DISH' }
ASA: SOAP and DISH Services
SOAP
Result set automatically formatted as a SOAP response
http://www.w3.org/TR/soap/
DISH
“Deduce Ideal SOAP Handler”
Groups SOAP services together
Generates WSDL
ASA SOAP Example
Introduction to .NET
ASA and ADO.NET
ASA and Web Services
UltraLite.NET
UltraLite.NET - Today
DatabaseManager ConnectionParms
Table
Column ColumnSchema
TableSchema IndexSchema
PreparedStatement ResultSet
ResultSetSchema
SyncResult
SyncParms
Using UltraLite.NET
Private Function NewProductList() As Boolean
Dim p As Table = _conn.GetTable("ULProduct")
p.Open("ULProductName")
Dim n As Long = p.RowCount
Dim i As Long = 0
If n > 0 Then
_prodNames = New String(n - 1) {}
_prodPrices = New Integer(n - 1) {}
Dim cid As Short = p.Schema.GetColumnID("prod_name")
Dim pid As Short = p.Schema.GetColumnID("price")
While p.MoveNext()
_prodNames(i) = p.GetString(cid)
_prodPrices(i) = p.GetInt(pid)
i = i + 1
End While
Else
_prodNames = Nothing
_prodPrices = Nothing
End If
p.Close()
Return True
End Function
Sneak Preview: UltraLite.NET for ADO.NET
Namespace is iAnywhere.Data.UltraLite
ASA: iAnywhere.Data.AsaClient
Benefits
Easy application migration to ASA
More familiar API for .NET developers
Demo: UltraLite.NET and ADO.NET
Summary
YES!
iAnywhere at TechWave2004
Developer Community
A one-stop source for technical information!
http://www.ianywhere.com/developer/
Questions?
Alex Reif
Product Manager
[email protected]