Using the .NET Data Provider in a Visual Studio project

The SQL Anywhere .NET Data Provider can be used to develop applications with Visual Studio 2005 or later versions. To use the SQL Anywhere .NET Data Provider, you must include two items in your Visual Studio project:

  • a reference to the SQL Anywhere .NET Data Provider DLL

  • a line in your source code referencing the SQL Anywhere .NET Data Provider classes

These steps are explained below.

For information about installing and registering the SQL Anywhere .NET Data Provider, see Deploying the SQL Anywhere .NET Data Provider.

Adding a reference to the Data Provider DLL in your project

Adding a reference tells Visual Studio which DLL to include to find the code for the SQL Anywhere .NET Data Provider.

To add a reference to the SQL Anywhere .NET Data Provider in a Visual Studio project
  1. Start Visual Studio and open your project.

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

  3. On the .NET tab, click Browse to locate iAnywhere.Data.SQLAnywhere.dll. Note that there are separate versions of the DLL for each of Windows and Windows Mobile platforms.

    • For the Windows SQL Anywhere .NET Data Provider, the default location is install-dir\Assembly\v2.

    • For the Windows Mobile SQL Anywhere .NET Data Provider, the default location is install-dir\ce\Assembly\v2.

  4. Select the DLL and then click Open.

    For a complete list of installed DLLs, see SQL Anywhere .NET Data Provider required files.

  5. You can verify that the DLL is added to your project. Open the Add Reference window and then click the .NET tab. iAnywhere.Data.SQLAnywhere.dll appears in the Selected Components list. Click OK to close the window.

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

Using the Data Provider classes in your source code

To assist with the use of the SQL Anywhere .NET Data Provider namespace and the types defined in this namespace, you should add a directive to your source code.

To use the Data Provider namespace in your code
  1. Start Visual Studio and open your project.

  2. 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

This directive is not required, however, it allows you to use short forms for the SQL Anywhere .NET classes. For example:

SAConnection conn = new SAConnection()

Without this directive, you can still use the following:

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