Switch to standard view 
  Sybase logo
 
 
 



Implementing SQL Anywhere Authenticated Edition in DataWindow .NET Environments

The patented Sybase DataWindow technology provides powerful data retrieval, manipulation, presentation, and update capabilities for client/server, multitier, and thin-client Web-based applications. DataWindow .NET lets you take advantage of the rich intercolor and ease-of-use of the DataWindow in the .NET environment. For the purpose of this document, Datawindow refers to the DatawindowControl, WebDataWindowControl, or DataStore.

This document will describe how to implement the SQL Anywhere Authenticated Edition in a DataWindow.Net implementation.

Datawindow .NET Database Connectivity

Datawindow .NET provides two classes that support the connection between a Datawindow and a database. The Transaction class provides basic control of the transaction including Connect, Disconnect, Commit, and Rollback methods. The Transaction class can only be used with Datawindows and provides limited access to the database. The AdoTransaction class should be used if there is a requirement to share a connection with other database constructions in your application such as a DataSet or Command objects.

Implementing Authentication

Authentication in a DataWindow .NET application requires the use of a Command object to set the option CONNECTION_AUTHENTICATION required to authenticate the connection. The steps to achieve an authenticated connection are:

  1. Create a new instance of an ADO.NET Connection object and set its properties
  2. Open an existing connection or create a new
  3. Create an AdoTransaction object that uses the Connection object and bind it to the internal database interaction layer
  4. Assign the AdoTransaction object to a DatawindowControl, WebDataWindowControl, or DataStore
  5. Set the CONNECTION_AUTHENTICATION option

 

A C# Example

The following example is written in C# and demonstrates the steps described previously. The code is shown in its entirety followed by a code walkthrough that highlights each of the steps required to authenticate the connection for use with Datawindow .NET technology.

// establish an authenticated connection
try

{
// get connected using the connection string value
// supplied in the textbox textBoxConnStr

OleDbConnection oleDbConn = new OleDbConnection();
oleDbConn.ConnectionString = textBoxConnStr.Text;

// open a connection
oleDbConn.Open();

// associate the connection to AdoTransaction
AdoTransaction adoTrans = new AdoTransaction(oleDbConn);
adoTrans.BindConnection();

// associate the AdoTransaction to the datawindow
dataWindowControlTest.SetTransaction(adoTrans);

// authenticate the connection
      OleDbCommand cmd = new OleDbCommand
("SET TEMPORARY OPTION CONNECTION_AUTHENTICATION='" +
textBoxConnAuthStr.Text + "'", oleDbConn);
      cmd.ExecuteNonQuery();

// initial retrieve
dataWindowControlTest.Retrieve();

// clean up connection
oleDbConn.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message,"Authentication Sample Failedfont>");
}

1. Create a new instance of an ADO.NET Connection object and set its properties

// get connected using the connection string value
// supplied in the textbox textBoxConnStr

OleDbConnection oleDbConn = new OleDbConnection();
oleDbConn.ConnectionString = textBoxConnStr.Text;

2. Open an existing connection or create a new

// open a connection
oleDbConn.Open();

3. Create an AdoTransaction object that uses the Connection object and bind it to the internal database interaction layer

// associate the connection to AdoTransaction
AdoTransaction adoTrans = new AdoTransaction(oleDbConn);
adoTrans.BindConnection();

4. Assign the AdoTransaction object to a DatawindowControl, WebDataWindowControl, or DataStore

// associate the AdoTransaction to the datawindow
dataWindowControl.SetTransaction(adoTrans);

5. Set the CONNECTION_AUTHENTICATION option at any time in advance of an operation that would modify the database.

// authenticate the connection
      OleDbCommand cmd = new OleDbCommand
("SET TEMPORARY OPTION CONNECTION_AUTHENTICATION='" +
textBoxConnAuthStr.Text + "'", oleDbConn);
      cmd.ExecuteNonQuery();



Back to Top
© Copyright 2010, Sybase Inc.