Using the .NET Data Provider in a Visual Studio project

Use the SQL Anywhere .NET Data Provider to develop .NET applications with Visual Studio by including both a reference to the SQL Anywhere .NET Data Provider, and a line in your source code referencing the SQL Anywhere .NET Data Provider classes.

Prerequisites

There are no prerequisites for this task.

Context and remarks

Many.

 Task
  1. Start Visual Studio and open your project.

  2. In the Solution Explorer window, right-click References and click Add Reference.

    The reference indicates which provider to include and locates the code for the SQL Anywhere .NET Data Provider.

  3. Click the .NET tab, and scroll through the list to locate any of the following:

    • iAnywhere.Data.SQLAnywhere for .NET 2
    • iAnywhere.Data.SQLAnywhere for .NET 3.5
    • iAnywhere.Data.SQLAnywhere for .NET 4
    Note

    There is separate version of the provider for Windows Mobile platforms. For the Windows Mobile SQL Anywhere .NET Data Provider, click the Browse tab and locate the Windows Mobile version of the provider. The default location is %SQLANY12%\CE\Assembly\V2.

  4. Click the desired provider and then click OK.

    The provider is added to the References folder in the Solution Explorer window of your project.

  5. Specify a directive to your source code to assist with the use of the SQL Anywhere .NET Data Provider namespace and the defined types.

    Add the following line to your project:

    • If you are using C#, add the following line to the list of using directives at the beginning of your project:

      using iAnywhere.Data.SQLAnywhere;
    • If you are using Visual Basic, add the following line at the beginning of your project before the line Public Class Form1:

      Imports iAnywhere.Data.SQLAnywhere

Results

The SQL Anywhere .NET Data Provider is set up for use with your .NET application.

Next

None.

Example

The following example illustrates code that can be used to establish a database connection when a directive is specified:

SAConnection conn = new SAConnection();

The following example illustrates code that can be used to establish a database connection when a directive is not specified:

iAnywhere.Data.SQLAnywhere.SAConnection conn = 
    new iAnywhere.Data.SQLAnywhere.SAConnection();

 See also