Sybase Business Intelligence Solutions - Database Management, Data Warehousing Software, Mobile Enterprise Applications and Messaging
Sybase Brand Color Bar
delete

Search for    in all of Sybase.com
view all search results right arrow
  blank
 
 
 
 
 
 
 
 
 
 

 
 
CLICK TO EXPAND NAVIGATION
CLICK TO EXPAND NAVIGATION
 
 
 
 
Support > Technical Documents > Document Types > White Paper-Technical > SQL Anywhere Integration with Visual Studio 2010

SQL Anywhere Integration with Visual Studio 2010
 
RSS Feed
 
 
 

Introduction

SQL Anywhere contains a number of integration features with Microsoft Visual Studio 2008 and 2010. These features are designed to make it easier to work with a SQL Anywhere database while developing an application using Visual Studio. This whitepaper outlines the integration features that are present for Visual Studio 2010 and contains short tutorials demonstrating how the integration features can be used to ease application development while working with a database.

Download paper

Download PDF Button -   41x45px

Requirements

SQL Anywhere .NET Integration Tools

The SQL Anywhere setup program automatically installs the .NET integration components to your Visual Studio 2010 installation. However, if you install Visual Studio 2010 after installing SQL Anywhere, you must install the SQL Anywhere integration tools:

  • Ensure Visual Studio is not running.
  • Open a Command Prompt and navigate to the following directory:
  • C:\Program Files\SQL Anywhere 12\Assembly\v2

  • Run the following command:

          SetupVSPackage.exe /i

If you want to un-install the integration tools:

  • Run the following command at the same directory:

          SetupVSPackage.exe /u

SQL Anywhere Data Providers

SQL Anywhere supports the Microsoft .NET Framework through the following namespaces.

iAnywhere.Data.SQLAnywhere   The ADO.NET object model is an all-purpose data access model. ADO.NET components were designed to factor data access from data manipulation. There are two central components of ADO.NET that do this: the DataSet, and the .NET Framework data provider, which is a set of components including the Connection, Command, DataReader, and DataAdapter objects. SQL Anywhere includes a .NET Framework Data Provider that communicates directly with a SQL Anywhere database server without adding the overhead of OLE DB or ODBC. The SQL Anywhere .NET Data Provider is represented in the .NET namespace as iAnywhere.Data.SQLAnywhere.

The Microsoft .NET Compact Framework is the smart device development framework for Microsoft .NET. The SQL Anywhere .NET Compact Framework Data Provider supports devices running Windows Mobile.

System.Data.Oledb   This namespace supports OLE DB data sources. This namespace is an intrinsic part of the Microsoft .NET Framework. You can use System.Data.Oledb together with the SQL Anywhere OLE DB provider, SAOLEDB, to access SQL Anywhere databases.

System.Data.Odbc   This namespace supports ODBC data sources. This namespace is an intrinsic part of the Microsoft .NET Framework. You can use System.Data.Odbc together with the SQL Anywhere ODBC driver to access SQL Anywhere databases.

On Windows Mobile, only the SQL Anywhere .NET Data Provider is supported.

There are some key benefits to using the SQL Anywhere .NET Data Provider:

In the .NET environment, the SQL Anywhere .NET Data Provider provides native access to a SQL Anywhere database. Unlike the other supported providers, it communicates directly with a SQL Anywhere server and does not require bridge technology. As a result, the SQL Anywhere .NET Data Provider is faster than the OLE DB and ODBC Data Providers. It is the recommended data provider for accessing SQL Anywhere databases.

Server Explorer Plug-in

The Visual Studio Server Explorer can be used to display information about databases, such as their schema and the data they contain.

  1. In Visual Studio, choose View > Server Explorer. The Server Explorer appears.

    Server Explorer in Visual Studio 2010

  2. Right-click Data Connections and choose Add Connection.
    The Add Connection dialog appears.
  3. If the Data Source is not set to SQL Anywhere (SQL Anywhere 12), click Change and select SQL Anywhere from the list.
  4. Select SQL Anywhere 12 Demo in the ODBC Data Source Name field.
  5. In the User ID field, type DBA, and in the Password field, type sql.

    Add a Connection to SQL Anywhere

  6. Click Test Connection to test the supplied parameters.
    A window appears and indicates whether the connection is successful or if there are problems.
  7. Click OK to add the connection.
    The Server Explorer now displays the new connection-SQL Anywhere.demo12.
  8. Expand the connection and the Tables entry below it.
    The Server Explorer shows you all the tables that are in your database. To view the schema for one of the tables, click + beside its name. For example, expand the Departments table to look at its schema:

    View the Sample Database in Server Explorer

    The Departments table contains three columns: DepartmentID, DepartmentName, and DepartmentHeadID.

Visual Studio Data Sources

Visual Studio can maintain a list of data sources for your application.

  1. Create a new project:

    a.  Choose File > New Project.

    b.  Under Visual C# or Visual Basic, click Windows Forms Application.

    c.  Enter the name of your application and click OK.

  2. To open the list of data sources or connect to a new data source, choose Data > Show Data Sources.
  3. Click Add New Data Source.
    The Data Source Configuration Wizard appears.
  4. Select the Database option, and then click Next.
  5. Select the Dataset option, and the click Next.
  6. The SQL Anywhere data connection you created in the Server Explorer is available. The wizard informs you that the connection string contains sensitive data. Click + beside Connection String. The connection string includes a user ID and password. Since these are the default settings for the database, you can store them in the connection string. Select Yes, Include Sensitive Data In The Connection String. Click Next.

    Add a Connection to SQL Anywhere

  7. Use the default name ConnectionString. Click Next.
  8. Include all of the tables and views in the dataset.

    Add Tables and Views

  9. Use the default name DataSet1. Click Finish to close the wizard and create the new data source. DataSet1 appears in the list of Data Sources:

    DataSet1 in the Data Sources Tab

    Elements from the DataSet can be dragged and dropped onto your form. For example, drag the Departments table onto your form. Visual Studio automatically creates the necessary bindings and table adapters, and supplies you with a graphical control that you can use to interact with the Departments table.

    Application Design View

  10. Compile and run the application by choosing Debug > Start Debugging.
    The table is filled with data from the database.

    Debugging Form1

  11. Add a new row by typing in the row with the asterisk beside it, or by clicking the + icon in the toolbar. By default, all of the data can be edited and saved to the database.
  12. To change the behavior of this control, stop the application, and view the properties in Visual Studio for the data grid. To disallow a user from editing the content, set the ReadOnly property to True.

    View the GridView Properties

  13. The Data Sources tab also allows you to view the contents of your DataSet. For example, expand the Departments table.

    View Departments Table

    This view shows you the columns that are in that table. It provides another quick way that you can view the table schema from within Visual Studio.

Entity Data Models

A SQL Anywhere database can also be used to create a new entity data model defined in Visual Studio 2010. Follow the steps below to add the SQL Anywhere 12 Demo database as a EDM to your project.

  1. Right-click your project,  click Add New Item > ADO.NET Entity Data Model.
  2. In the Name field, type SQLAnyEDM.edmx. Click Add.

    Add ADO.NET Entity Data Model to the Project

  3. Select Generate from database and click Next.
  4. Skip step 4 - 6 if the default connection is SQL Anywhere.demo12. Otherwise, click New Connection.
  5. In the Data source list, click SQL Anywhere. Click Continue.

    ** If SQL Anywhere does not appear in the Data source list, verify the SQL Anywhere integration components are installed properly.

  6. Click ODBC Data Source name and select SQL Anywhere 12 Demo. Click OK.
  7. Click Next.
  8. Include all database objects in the model and Click Finish.

    Add Database Objects to the EDM

  9. Open SQLAnyEDM.edmx file , a visual representation of the model appears in the Entity Designer. In the diagram below, the generated properties and associations match the database schema.

View Database Schema Using Entity Designer and Sybase Central

Summary

This paper provided an overview of the Server Explorer plug-in and controls available in Visual Studio 2010. It also illustrated how to use the a Dataset object to display information retrieved from a SQL Anywhere database and how to create a Entity Data Model using the SQL Anywhere demo database.


 

Related Links

DOCUMENT ATTRIBUTES
Last Revised: Jul 19, 2010
Product: SQL Anywhere
Technical Topics: SQL Anywhere, Microsoft.NET, SQL ISV Applications, Microsoft Visual Studio, SQL Server Applications
  
Business or Technical: Technical
Content Id: 1080131
Infotype: White Paper-Technical
 
 
 

 
© Copyright 2014, Sybase Inc. - v 7.6 Home / Contact Us / Help / Jobs / Legal / Privacy / Code of Ethics