connector net en.a4

354

Click here to load reader

Upload: wawa-geulis

Post on 24-Sep-2015

247 views

Category:

Documents


12 download

DESCRIPTION

koneksi My Sql

TRANSCRIPT

  • MySQL Connector/Net Developer Guide

  • Abstract

    This manual describes how to install and configure MySQL Connector/Net, the driver that enables .NETapplications to communicate with MySQL servers, and how to use it to develop database applications.

    For notes detailing the changes in each release of Connector/Net, see MySQL Connector/Net Release Notes.

    Document generated on: 2015-05-25 (revision: 43258)

  • iii

    Table of ContentsPreface and Legal Notices .......................................................................................................... vii1 Introduction to MySQL Connector/Net ........................................................................................ 12 Connector/Net Versions ............................................................................................................. 33 Connector/Net Installation .......................................................................................................... 7

    3.1 Installing Connector/Net on Windows .............................................................................. 73.1.1 Installing Connector/Net Using MySQL Installer ..................................................... 73.1.2 Installing Connector/Net Using the Standalone Installer .......................................... 7

    3.2 Installing Connector/Net on Unix with Mono ................................................................... 103.3 Installing Connector/Net from the Source Code .............................................................. 11

    4 Connector/Net Visual Studio Integration ................................................................................... 134.1 Installing and Configuring .............................................................................................. 134.2 Making a Connection .................................................................................................... 154.3 The MySQL Toolbar ..................................................................................................... 174.4 Using IntelliSense in the SQL Editor .............................................................................. 184.5 Editing Tables .............................................................................................................. 18

    4.5.1 Column Editor ................................................................................................... 204.5.2 Editing Indexes .................................................................................................. 214.5.3 Editing Foreign Keys .......................................................................................... 214.5.4 Column Properties ............................................................................................. 224.5.5 Table Properties ................................................................................................ 23

    4.6 Editing Views ............................................................................................................... 254.7 Editing Stored Procedures and Functions ...................................................................... 274.8 Editing Triggers ............................................................................................................ 294.9 Debugging Stored Procedures and Functions ................................................................. 304.10 Deleting Database Objects .......................................................................................... 394.11 Using the ADO.NET Entity Framework ......................................................................... 394.12 MySQL Website Configuration Tool ............................................................................. 394.13 Windows Forms Project Wizard ................................................................................... 48

    4.13.1 Requirements .................................................................................................. 484.13.2 Usage: Creating A New Windows Forms Application .......................................... 484.13.3 Additional Notes ............................................................................................... 56

    4.14 MySQL ASP.NET MVC Project Wizard ........................................................................ 574.14.1 Requirements .................................................................................................. 574.14.2 Usage: Creating A New MVC Web Application .................................................. 58

    4.15 MySQL SQL Editor ..................................................................................................... 624.16 MySQL Data Export Tool ............................................................................................ 634.17 DDL T4 Template Macro ............................................................................................. 69

    5 Connector/Net Tutorials ........................................................................................................... 715.1 Tutorial: An Introduction to Connector/Net Programming ................................................. 71

    5.1.1 The MySqlConnection Object ............................................................................. 715.1.2 The MySqlCommand Object ............................................................................... 725.1.3 Working with Decoupled Data ............................................................................ 745.1.4 Working with Parameters ................................................................................... 775.1.5 Working with Stored Procedures ......................................................................... 79

    5.2 Tutorial: MySQL Connector/Net ASP.NET Membership and Role Provider ........................ 805.3 Tutorial: MySQL Connector/Net ASP.NET Session State Provider ................................... 855.4 Tutorial: MySQL Connector/Net ASP.NET Profile Provider .............................................. 875.5 Tutorial: Web Parts Personalization Provider .................................................................. 905.6 Tutorial: Simple Membership Web Provider .................................................................... 93

    5.6.1 Requirements .................................................................................................... 945.6.2 Creating and Configuring a New Project .............................................................. 945.6.3 Adding OAuth Authentication to a Project ............................................................ 97

    5.7 Tutorial: Using an Entity Framework Entity as a Windows Forms Data Source ................. 1005.8 Tutorial: Databinding in ASP.NET Using LINQ on Entities ............................................. 1125.9 Tutorial: Using SSL with MySQL Connector/Net ........................................................... 117

  • MySQL Connector/Net Developer Guide

    iv

    5.10 Tutorial: Using MySqlScript ....................................................................................... 1195.10.1 Using Delimiters with MySqlScript ................................................................... 120

    5.11 Tutorial: Generating MySQL DDL from an Entity Framework Model .............................. 1226 Connector/Net Programming .................................................................................................. 123

    6.1 Connecting to MySQL Using Connector/Net ................................................................. 1246.2 Creating a Connector/Net Connection String ................................................................ 124

    6.2.1 Opening a Connection ..................................................................................... 1246.2.2 Handling Connection Errors .............................................................................. 1266.2.3 Using GetSchema on a Connection .................................................................. 127

    6.3 Using MySqlCommand ................................................................................................ 1296.4 Using Connector/Net with Connection Pooling .............................................................. 1306.5 Using the Windows Native Authentication Plugin .......................................................... 1306.6 Writing a Custom Authentication Plugin ....................................................................... 1316.7 MySQL Fabric Support ............................................................................................... 1346.8 Using Connector/Net with Table Caching ..................................................................... 1396.9 Using the Connector/Net with Prepared Statements ...................................................... 140

    6.9.1 Preparing Statements in Connector/Net ............................................................. 1406.10 Accessing Stored Procedures with Connector/Net ....................................................... 141

    6.10.1 Using Stored Routines from Connector/Net ...................................................... 1426.11 Handling BLOB Data With Connector/Net ................................................................... 144

    6.11.1 Preparing the MySQL Server .......................................................................... 1456.11.2 Writing a File to the Database ........................................................................ 1456.11.3 Reading a BLOB from the Database to a File on Disk ...................................... 147

    6.12 Asynchronous methods ............................................................................................. 1486.13 Using the Connector/Net Interceptor Classes .............................................................. 1546.14 Handling Date and Time Information in Connector/Net ................................................ 156

    6.14.1 Fractional Seconds ......................................................................................... 1566.14.2 Problems when Using Invalid Dates ................................................................ 1566.14.3 Restricting Invalid Dates ................................................................................. 1566.14.4 Handling Invalid Dates ................................................................................... 1566.14.5 Handling NULL Dates ..................................................................................... 157

    6.15 Using the MySqlBulkLoader Class ............................................................................. 1576.16 Using the MySQL Connector/Net Trace Source Object ................................................ 159

    6.16.1 Viewing MySQL Trace Information .................................................................. 1606.16.2 Building Custom Listeners .............................................................................. 162

    6.17 Binary/Nonbinary Issues ............................................................................................ 1646.18 Character Set Considerations for Connector/Net ......................................................... 1646.19 Using Connector/Net with Crystal Reports .................................................................. 165

    6.19.1 Creating a Data Source .................................................................................. 1656.19.2 Creating the Report ........................................................................................ 1666.19.3 Displaying the Report ..................................................................................... 166

    6.20 ASP.NET Provider Model .......................................................................................... 1696.21 Working with Partial Trust / Medium Trust .................................................................. 171

    6.21.1 Evolution of Partial Trust Support Across Connector/Net Versions ..................... 1716.21.2 Configuring Partial Trust with Connector/Net Library Installed in GAC ................ 1726.21.3 Configuring Partial Trust with Connector/Net Library Not Installed in GAC ........... 174

    7 Connector/Net Connection String Options Reference ............................................................... 1778 Connector/Net Support for Windows Store .............................................................................. 1859 EF 5 Support ........................................................................................................................ 18710 EF 6 Support ...................................................................................................................... 19111 Connector/Net API Reference .............................................................................................. 197

    11.1 MySql.Data.MySqlClient Namespace ......................................................................... 19711.1.1 MySql.Data.MySqlClientHierarchy ................................................................... 19811.1.2 BaseCommandInterceptor ............................................................................... 19811.1.3 BaseExceptionInterceptor ............................................................................... 19911.1.4 MySqlCommand Class ................................................................................... 19911.1.5 MySqlCommandBuilder Class ......................................................................... 26511.1.6 MySqlException Class .................................................................................... 283

  • MySQL Connector/Net Developer Guide

    v

    11.1.7 MySqlHelper Class ......................................................................................... 28411.1.8 MySqlErrorCode Enumeration ......................................................................... 295

    11.2 MySql.Data.Types Namespace .................................................................................. 29511.2.1 MySql.Data.TypesHierarchy ............................................................................ 29511.2.2 MySqlConversionException Class ................................................................... 29611.2.3 MySqlDateTime Class .................................................................................... 297

    12 Connector/Net Support ........................................................................................................ 33912.1 Connector/Net Community Support ............................................................................ 33912.2 How to Report Connector/Net Problems or Bugs ........................................................ 339

    13 Connector/Net FAQ ............................................................................................................. 341A Licenses for Third-Party Components ..................................................................................... 343

    A.1 ANTLR 3.3 License .................................................................................................... 343A.2 Bouncy Castle 1.7 License ......................................................................................... 344A.3 RFC 3174 - US Secure Hash Algorithm 1 (SHA1) License ............................................ 344A.4 SSH.NET Library License ........................................................................................... 345A.5 zlib License ................................................................................................................ 345A.6 ZLIB.NET License ...................................................................................................... 346

  • vi

  • vii

    Preface and Legal NoticesThis manual describes how to install, configure, and develop database applications using MySQLConnector/Net, the driver that allows .NET applications to communicate with MySQL servers.

    Legal NoticesCopyright 2004, 2015, Oracle and/or its affiliates. All rights reserved.

    This software and related documentation are provided under a license agreement containingrestrictions on use and disclosure and are protected by intellectual property laws. Except as expresslypermitted in your license agreement or allowed by law, you may not use, copy, reproduce, translate,broadcast, modify, license, transmit, distribute, exhibit, perform, publish, or display any part, in anyform, or by any means. Reverse engineering, disassembly, or decompilation of this software, unlessrequired by law for interoperability, is prohibited.

    The information contained herein is subject to change without notice and is not warranted to be error-free. If you find any errors, please report them to us in writing.

    If this software or related documentation is delivered to the U.S. Government or anyone licensing it onbehalf of the U.S. Government, the following notice is applicable:

    U.S. GOVERNMENT RIGHTS Programs, software, databases, and related documentation andtechnical data delivered to U.S. Government customers are "commercial computer software" or"commercial technical data" pursuant to the applicable Federal Acquisition Regulation and agency-specific supplemental regulations. As such, the use, duplication, disclosure, modification, andadaptation shall be subject to the restrictions and license terms set forth in the applicable Governmentcontract, and, to the extent applicable by the terms of the Government contract, the additional rights setforth in FAR 52.227-19, Commercial Computer Software License (December 2007). Oracle USA, Inc.,500 Oracle Parkway, Redwood City, CA 94065.

    This software is developed for general use in a variety of information management applications. It is notdeveloped or intended for use in any inherently dangerous applications, including applications whichmay create a risk of personal injury. If you use this software in dangerous applications, then you shallbe responsible to take all appropriate fail-safe, backup, redundancy, and other measures to ensure thesafe use of this software. Oracle Corporation and its affiliates disclaim any liability for any damagescaused by use of this software in dangerous applications.

    Oracle is a registered trademark of Oracle Corporation and/or its affiliates. MySQL is a trademarkof Oracle Corporation and/or its affiliates, and shall not be used without Oracle's express writtenauthorization. Other names may be trademarks of their respective owners.

    This software and documentation may provide access to or information on content, products, andservices from third parties. Oracle Corporation and its affiliates are not responsible for and expresslydisclaim all warranties of any kind with respect to third-party content, products, and services. OracleCorporation and its affiliates will not be responsible for any loss, costs, or damages incurred due toyour access to or use of third-party content, products, or services.

    This document in any form, software or printed matter, contains proprietary information that is theexclusive property of Oracle. Your access to and use of this material is subject to the terms andconditions of your Oracle Software License and Service Agreement, which has been executed and withwhich you agree to comply. This document and information contained herein may not be disclosed,copied, reproduced, or distributed to anyone outside Oracle without prior written consent of Oracleor as specifically provided below. This document is not part of your license agreement nor can it beincorporated into any contractual agreement with Oracle or its subsidiaries or affiliates.

    This documentation is NOT distributed under a GPL license. Use of this documentation is subject to thefollowing terms:

  • Legal Notices

    viii

    You may create a printed copy of this documentation solely for your own personal use. Conversionto other formats is allowed as long as the actual content is not altered or edited in any way. You shallnot publish or distribute this documentation in any form or on any media, except if you distribute thedocumentation in a manner similar to how Oracle disseminates it (that is, electronically for downloadon a Web site with the software) or on a CD-ROM or similar medium, provided however that thedocumentation is disseminated together with the software on the same medium. Any other use, suchas any dissemination of printed copies or use of this documentation, in whole or in part, in anotherpublication, requires the prior written consent from an authorized representative of Oracle. Oracle and/or its affiliates reserve any and all rights to this documentation not expressly granted above.

    For more information on the terms of this license, or for details on how the MySQL documentation isbuilt and produced, please visit MySQL Contact & Questions.

    For help with using MySQL, please visit either the MySQL Forums or MySQL Mailing Lists where youcan discuss your issues with other MySQL users.

    For additional documentation on MySQL products, including translations of the documentation intoother languages, and downloadable versions in variety of formats, including HTML and PDF formats,see the MySQL Documentation Library.

  • 1Chapter 1 Introduction to MySQL Connector/NetConnector/Net lets you easily develop .NET applications that require secure, high-performancedata connectivity with MySQL. It implements the required ADO.NET interfaces and integrates intoADO.NET-aware tools. Developers can build applications using their choice of .NET languages.Connector/Net is a fully managed ADO.NET driver written in 100% pure C#. It does not use the MySQLC client library.

    For notes detailing the changes in each release of Connector/Net, see MySQL Connector/Net ReleaseNotes.

    Connector/Net includes full support for:

    Features provided by MySQL Server up to and including MySQL Server 5.7.

    Large-packet support for sending and receiving rows and BLOB values up to 2 gigabytes in size.

    Protocol compression, which enables compressing the data stream between the client and server.

    Connections using TCP/IP sockets, named pipes, or shared memory on Windows.

    Connections using TCP/IP sockets or Unix sockets on Unix.

    The Open Source Mono framework developed by Novell.

    Microsoft Entity Framework.

    Microsoft Windows RT.

    This document is intended as a user's guide to Connector/Net and includes a full syntax reference.Syntax information is also included within the MySql.Data.chm file included with the Connector/Netdistribution.

    If you are using MySQL 5.0 or later, and Visual Studio as your development environment, you can alsouse the MySQL Visual Studio Plugin. The plugin acts as a DDEX (Data Designer Extensibility) provider:you can use the data design tools within Visual Studio to manipulate the schema and objects within aMySQL database. For more information, see Chapter 4, Connector/Net Visual Studio Integration.

    Note

    From Connector/Net 5.1 through 6.6, the Visual Studio Plugin is part of the mainConnector/Net package. Starting with 6.7, the Visual Studio Plugin has beenseparated out into it's own product. The MySQL for Visual Studio Plugin releasenotes can be found at MySQL Connector/Net Release Notes.

    MySQL Connector/Net supports full versions of Visual Studio 2008, 2010, and 2012, although theextent of support may be limited depending on your versions of MySQL Connector/Net and VisualStudio. For details, see Chapter 4, Connector/Net Visual Studio Integration.

    MySQL Connector/Net does not support Express versions of Microsoft products, including MicrosoftVisual Web Developer.

    Key Topics For connection string properties when using the MySqlConnection class, see Chapter 7,

    Connector/Net Connection String Options Reference.

  • 2

  • 3Chapter 2 Connector/Net VersionsThere are several versions of Connector/Net available:

    Connector/Net 6.9 includes new features such as a MySQL Personalization provider, SiteMapWeb provider, a simple Membership Web provider, and support for MySQL for Visual Studio 1.2.

    Connector/Net 6.8 includes new features such as Entity Framework 6 support, addedidempotent script for Entity Framework 6 migrations, changed EF migration history table to use asingle column as primary key, removed installer validation when MySQL for Visual Studio is installed,and support for MySQL for Visual Studio 1.1.

    Connector/Net 6.7 includes new features such as Entity Framework 5 support, built-in LoadBalancing (to be used with a backend implementing either MySQL Replication or MySQL Clustering),a Memcached client (compatible with Innodb Memcached plugin) and support for WindowsRuntime (WinRT) to write store apps. This version also removes all features related to Visual StudioIntegration, which are provided in a separate product, MySQL for Visual Studio.

    Connector/Net 6.6 includes new features such as stored procedure debugging in MicrosoftVisual Studio, support for pluggable authentication including the ability to write your ownauthentication plugins, Entity Framework 4.3 Code First support, and enhancements to partial trustsupport to allow hosting services to deploy applications without installing the Connector/Net library inthe GAC.

    Connector/Net 6.5 includes new features such as interceptor classes for exceptions andcommands, support for the MySQL 5.6+ fractional seconds feature, better partial-trust support, andbetter IntelliSense, including auto-completion when editing stored procedures or .mysql files.

    Connector/Net 6.4 includes new features such as support for Windows authentication (whenconnecting to MySQL Server 5.5+), table caching on the client side, simple connection fail-oversupport, and improved SQL generation from the Entity Framework provider.

    This version of Connector/Net is no longer supported.

    Connector/Net 6.3 includes new features such as integration with Visual Studio 2010, such asthe availability of DDL T4 template for Entity Framework, and a custom MySQL SQL Editor. Otherfeatures include refactored transaction scope: Connector/Net now supports nested transactions in ascope where they use the same connection string.

    This version of Connector/Net is no longer supported.

    Connector/Net 6.2 includes new features such as a new logging system and client SSLcertificates.

    This version of Connector/Net is no longer supported.

    Connector/Net 6.1 includes new features such as the MySQL Website Configuration Tool, and aSession State Provider.

    This version of Connector/Net is no longer supported.

    Connector/Net 6.0 includes support for UDF schema collection, Initial Entity Framework, anduse of the traditional SQL Server buttons in Visual Studio for keys, indexes, and so on.

    This version of Connector/Net is no longer supported.

    Connector/Net 5.2 includes support for a new membership/role provider, Compact Framework2.0, a new stored procedure parser and improvements to GetSchema. Connector/Net 5.2 alsoincludes the Visual Studio Plugin as a standard installable component.

    This version of Connector/Net is no longer supported.

  • 4 Connector/Net 5.1 includes support for a new membership/role provider, Compact Framework2.0, a new stored procedure parser and improvements to GetSchema. Connector/Net 5.1 alsoincludes the Visual Studio Plugin as a standard installable component.

    This version of Connector/Net is no longer supported.

    Connector/Net 5.0 includes full support for the ADO.Net 2.0 interfaces and subclasses, includessupport for the usage advisor and performance monitor (PerfMon) hooks.This version of Connector/Net is no longer supported.

    Connector/Net 1.0 includes full compatibility with the ADO.NET driver interface.

    This version of Connector/Net is no longer supported.

    The following table shows the .NET Framework version required, and the MySQL Server versionsupported by Connector/Net:

    Table 2.1 Connector/Net Requirements for Related Products

    Connector/Netversion

    ADO.NET versionsupported

    .NET Frameworkversion required

    MySQL Serverversionsupported

    Currentlysupported

    6.9 2.x+ 2.x+ for VS 2008,4.x+ for VS 2010 /2012 / 2013, .NETRT for VS 2012 /2013

    5.7, 5.6, 5.5, 5.1,5.0

    Yes

    6.8 2.x+ 2.x+ for VS2008, 4.x+ forVS 2010 / 2012 /2013, .NET RT forVS 2012/2013

    5.7, 5.6, 5.5, 5.1,5.0

    Yes

    6.7 2.x+ 2.x+ for VS2008, 4.x+ forVS 2010 / 2012 /2013, .NET RT forVS 2012/2013

    5.7, 5.6, 5.5, 5.1,5.0

    Yes

    6.6 2.x+ 2.x+ for VS 2008,4.x+ for VS 2010 /2012 / 2013

    5.7, 5.6, 5.5, 5.1,5.0

    Yes

    6.5 2.x+ 2.x+ for VS 2008,4.x+ for VS 2010

    5.7, 5.6, 5.5, 5.1,5.0

    No

    6.4 2.x+ 2.x+, 4.x+ for VS2010

    5.6, 5.5, 5.1, 5.0 No

    6.3 2.x+ 2.x+, 4.x+ for VS2010

    5.6, 5.5, 5.1, 5.0 No

    6.2 2.x+ 2.x+ 5.6, 5.5, 5.1, 5.0,4.1

    No

    6.1 2.x+ 2.x+ 5.6, 5.5, 5.1, 5.0,4.1

    No

    6.0 2.x+ 2.x+ 5.5, 5.1, 5.0, 4.1 No5.2 2.x+ 2.x+ 5.5, 5.1, 5.0, 4.1 No5.1 2.x+ 2.x+ 5.5, 5.1, 5.0, 4.1,

    4.0No

  • 5Connector/Netversion

    ADO.NET versionsupported

    .NET Frameworkversion required

    MySQL Serverversionsupported

    Currentlysupported

    5.0 2.x+ 2.x+ 5.0, 4.1, 4.0 No1.0 1.x 1.x 5.0, 4.1, 4.0 No

    Note

    Version numbers for MySQL products are formatted as X.Y.Z, where Z=0indicates alpha, Z=1 indicates beta, and Z>=2 indicates GA. However, Windowstools (Control Panel, properties display) may show the version numbers asXX.YY.ZZ. For example, the official MySQL formatted version number 5.0.9may be displayed by Windows tools as 5.00.09. The two versions are the same;only the number display format is different.

  • 6

  • 7Chapter 3 Connector/Net Installation

    Table of Contents3.1 Installing Connector/Net on Windows ...................................................................................... 7

    3.1.1 Installing Connector/Net Using MySQL Installer ............................................................. 73.1.2 Installing Connector/Net Using the Standalone Installer .................................................. 7

    3.2 Installing Connector/Net on Unix with Mono ........................................................................... 103.3 Installing Connector/Net from the Source Code ...................................................................... 11

    Connector/Net runs on any platform that supports the .NET framework. The .NET framework isprimarily supported on recent versions of Microsoft Windows, and is supported on Linux through theOpen Source Mono framework.

    MySQL Connector/Net is available for download from the MySQL Installer, as a standalone .msi, orfrom the MySQL NuGet repository.

    3.1 Installing Connector/Net on WindowsOn Microsoft Windows, you can install either through a binary installation process using a Connector/Net MSI, choose the MySQL Connector/Net product from the MySQL Installer, using Nuget, or bydownloading and using the Source.

    Before installing, ensure that your system is up to date, including installing the latest version ofthe .NET Framework.

    3.1.1 Installing Connector/Net Using MySQL InstallerMySQL Installer provides an easy to use, wizard-based installation experience for all MySQL softwareon Windows. It can be used to install and upgrade your MySQL Connector/Net installation.

    To use, download and install MySQL Installer.

    After executing MySQL Installer, choose and install the MySQL Connector/Net product.

    3.1.2 Installing Connector/Net Using the Standalone InstallerYou install Connector/Net through a Windows Installer (.msi) installation package, which can installConnector/Net on supported Windows operating systems. The MSI package is a file named mysql-connector-net-version.msi, where version indicates the Connector/Net version.

    Note

    Using the central MySQL Installer is recommended, instead of the standalonepackage that is documented in this section. The MySQL Installer is available fordownload at MySQL Installer.

    To install Connector/Net:

    1. Double-click the MSI installer file, and click Next to start the installation.

  • Installing Connector/Net Using the Standalone Installer

    8

    Figure 3.1 Connector/Net Installation: Welcome

    2. You must choose the type of installation to perform.

    Figure 3.2 Connector/Net Installation: Choose Setup Type

    For most situations, the Typical installation is suitable. Click the Typical button and proceed to Step5. A Complete installation installs all the available files. To conduct a Complete installation, clickthe Complete button and proceed to step 5. To customize your installation, including choosing thecomponents to install and some installation options, click the Custom button and proceed to Step 3.

    The Connector/Net installer will register the connector within the Global Assembly Cache (GAC) -this will make the Connector/Net component available to all applications, not just those where youexplicitly reference the Connector/Net component. The installer will also create the necessary linksin the Start menu to the documentation and release notes.

    3. If you have chosen a custom installation, you can select the individual components to install,including the core interface component, supporting documentation (a CHM file) samples andexamples, and the source code. Select the items, and their installation level, and then click Next tocontinue the installation.

  • Installing Connector/Net Using the Standalone Installer

    9

    Figure 3.3 Connector/Net Installation: Custom Setup

    4. You will be given a final opportunity to confirm the installation. Click Install to copy and install thefiles onto your machine.

    Figure 3.4 Connector/Net Installation: Ready To Begin

    5. Once the installation has been completed, click Finish to exit the installer.

  • Installing Connector/Net on Unix with Mono

    10

    Figure 3.5 Connector/Net Installation: Finish Installation

    Unless you choose otherwise, Connector/Net is installed in C:\Program Files (x86)\MySQL\MySQL Connector Net X.X.X, where X.X.X is replaced with the version of Connector/Net youare installing. New installations do not overwrite existing versions of Connector/Net.

    Depending on your installation type, the installed components will include some or all of the followingcomponents:

    Assemblies: Connector/Net MySQL libraries for different versions of the .NET environment.

    Documentation: Connector/Net documentation in CHM format.

    Samples: Sample code and applications that use the Connector/Net component.

    You may also use the /quiet or /q command-line option with the msiexec tool to install theConnector/Net package automatically (using the default options) with no notification to the user. Usingthis method the user cannot select options. Additionally, no prompts, messages or dialog boxes will bedisplayed.

    C:\> msiexec /package connector-net.msi /quiet

    To provide a progress bar to the user during automatic installation, use the /passive option.

    3.2 Installing Connector/Net on Unix with MonoThere is no installer available for installing the Connector/Net component on your Unix installation.Before installing, ensure that you have a working Mono project installation. To test whether yoursystem has Mono installed, enter:

    shell> mono --version

    The version of the Mono JIT compiler is displayed.

    To compile C# source code, make sure a Mono C# compiler is installed.

    Note

    There are three Mono C# compilers available: mcs, which accesses the 1.0-profile libraries, gmcs, which accesses the 2.0-profile libraries, and dmcs, whichaccesses the 4.0-profile libraries.

  • Installing Connector/Net from the Source Code

    11

    To install Connector/Net on Unix/Mono:

    1. Download the mysql-connector-net-version-noinstall.zip and extract the contents to adirectory of your choice, for example: ~/connector-net/.

    2. In the directory where you unzipped the connector to, change into the bin subdirectory. Ensure thefile MySql.Data.dll is present. This filename is case-sensitive.

    3. You must register the Connector/Net component, MySql.Data, in the Global Assembly Cache(GAC). In the current directory enter the gacutil command:

    root-shell> gacutil /i MySql.Data.dll

    This will register MySql.Data into the GAC. You can check this by listing the contents of /usr/lib/mono/gac, where you will find MySql.Data if the registration has been successful.

    You are now ready to compile your application. You must ensure that when you compile yourapplication you include the Connector/Net component using the -r: command-line option. Forexample:

    shell> gmcs -r:System.dll -r:System.Data.dll -r:MySql.Data.dll HelloWorld.cs

    The referenced assemblies depend on the requirements of the application, but applications usingMySQL Connector/Net must provide -r:MySql.Data at a minimum.

    You can further check your installation by running the compiled program, for example:

    shell> mono HelloWorld.exe

    3.3 Installing Connector/Net from the Source CodeSource packages of Connector/Net are available for download from http://dev.mysql.com/downloads/connector/net/.

    The file contains the following directories:

    Documentation: Source files to build the documentation into the compiled HTML (CHM) format,code examples, collection files, and licenses for third-party components.

    Samples: Source files for several example applications.

    Source\MySQL.ConnectorInstaller: Source files to build the Connector/Net installer program.

    Source\MySQL.Data: Source files for the core data provider.

    Source\MySQL.Data.Entity: Source files for the Entity Framework.

    Source\MySQL.Web: Source files for the web providers, including the membership/role/profileproviders that are used in ASP.NET web sites.

    Tests: Test cases for Connector/Net.

    Building the Source Code on Microsoft WindowsThe following procedure can be used to build the connector on Microsoft Windows.

    Navigate to the root of the source code tree.

    A Microsoft Visual Studio solution file named MySqlClient.sln is available to build the connector.Click this file to load the solution into Visual Studio.

  • Building the Source Code on Unix

    12

    MySqlClient.sln must be compiled with VS 2008, VS 2010, or VS 2012. Also, depending onthe version, the dependencies to build it include Visual Studio SDK, NUnit, Entity Framework, andANTLR Integration for Visual Studio.

    Select Build, Build Solution from the main menu to build the solution.

    Building the Source Code on UnixSupport for building Connector/Net on Mono/Unix is not available.

  • 13

    Chapter 4 Connector/Net Visual Studio Integration

    Table of Contents4.1 Installing and Configuring ...................................................................................................... 134.2 Making a Connection ............................................................................................................ 154.3 The MySQL Toolbar ............................................................................................................. 174.4 Using IntelliSense in the SQL Editor ...................................................................................... 184.5 Editing Tables ...................................................................................................................... 18

    4.5.1 Column Editor ........................................................................................................... 204.5.2 Editing Indexes .......................................................................................................... 214.5.3 Editing Foreign Keys .................................................................................................. 214.5.4 Column Properties ..................................................................................................... 224.5.5 Table Properties ........................................................................................................ 23

    4.6 Editing Views ....................................................................................................................... 254.7 Editing Stored Procedures and Functions .............................................................................. 274.8 Editing Triggers .................................................................................................................... 294.9 Debugging Stored Procedures and Functions ......................................................................... 304.10 Deleting Database Objects .................................................................................................. 394.11 Using the ADO.NET Entity Framework ................................................................................ 394.12 MySQL Website Configuration Tool ..................................................................................... 394.13 Windows Forms Project Wizard ........................................................................................... 48

    4.13.1 Requirements .......................................................................................................... 484.13.2 Usage: Creating A New Windows Forms Application .................................................. 484.13.3 Additional Notes ....................................................................................................... 56

    4.14 MySQL ASP.NET MVC Project Wizard ................................................................................ 574.14.1 Requirements .......................................................................................................... 574.14.2 Usage: Creating A New MVC Web Application .......................................................... 58

    4.15 MySQL SQL Editor ............................................................................................................. 624.16 MySQL Data Export Tool .................................................................................................... 634.17 DDL T4 Template Macro ..................................................................................................... 69

    With MySQL's support for Visual Studio, developers can work seamlessly with MySQL Connector/Netin the familiar Visual Studio environment.

    The MySQL for Visual Studio release notes can be found here.

    Visit the MySQL for Visual Studio forum for additional help and support.

    4.1 Installing and ConfiguringMySQL for Visual Studio is a product for Microsoft Windows, and it is installed with MySQL Installer, oralternatively from its own MSI.

    Using MySQL Installer: Download and execute the MySQL Installer. Select the MySQL for VisualStudio product and then proceed with the installation. See the MySQL Installer manual for additionaldetails.

    Standalone: As a Zip or MSI file.

    Note

    Many MySQL for Visual Studio features require MySQL Connector/Net installedon the same system, and MySQL Connector/Net is a separate download.

  • Requirements

    14

    RequirementsMySQL Connector/Net supports full versions of Visual Studio 2008 and later, although the extent ofsupport is based on your installed versions of MySQL Connector/Net and Visual Studio:

    Visual Studio 2013 (Professional edition and up, or Community edition) is supported by MySQLConnector/Net 6.8 and up with the MySQL for Visual Studio product.

    Visual Studio 2012 is supported by MySQL Connector/Net 6.7 with MySQL for Visual Studio, and byMySQL Connector/Net 6.6 with the older Visual Studio Plugin.

    The following table shows the support information for MySQL for Visual Studio:

    Table 4.1 Support Information for MySQL for Visual Studio

    MySQL forVisual StudioVersion

    Connector/Net VersionSupported

    Visual StudioVersionSupported

    MySQL ServerVersionsSupported

    CurrentlySupported

    Notes

    1.2 6.9,6.8 2008, 2010,2012, 2013

    5.7, 5.6, 5.5,5.1, 5.0

    Yes Some featuresrequire C/Net6.9

    1.1 6.8 2008, 2010,2012, 2013

    5.7, 5.6, 5.5,5.1, 5.0

    Yes

    1.0 6.7 2008, 2010,2012

    5.7, 5.6, 5.5,5.1, 5.0

    Yes

    MySQL Connector/Net and MySQL for Visual Studio are two separate products and can be usedwithout one another. However, the following restrictions apply:

    Always install the MySQL for Visual Studio before installing MySQL Connector/Net.

    MySQL for Visual Studio cannot be installed alongside any version of MySQL Connector/Net 6.6and before, which has to be removed before installing MySQL for Visual Studio.

    The following functions of MySQL for Visual Studio require MySQL Connector/Net to be installed:

    Entity Framework Designer, when using the Data Base First or the Model First approach.

    Web Configuration Tool

    Full integration with Visual Studio 2010 is available only with MySQL Connector/Net 6.3.2 and up,although applications using earlier versions of the connector can be built with the Visual Studio2010 environment using .NET 2.x frameworks. Since version 6.3.2 onwards, MySQL Connector/Nethas been shipped with both .NET 2.x and .NET 4.x versions of the entity framework support files,mysql.data.ef.dll and mysql.visualstudio.dll. The .NET 4.x versions are required toenable new integration features supported in Visual Studio 2010, including:

    New DDL T4 template for the Entity Framework (EF) - This enables developers to design anEF model from scratch and use the native Visual Studio 2010 facility to generate MySQL DDLfrom that model. This is done by creating the model, and with the model open, choosing theSSDLToMySQL template in the properties window. The correct DDL is then generated. Thedeveloper can then save this code as a .mysql file in their project and execute it against theMySQL server.

    New SQL Editor - A new SQL editor lets you connect to a MySQL server to execute SQL. This isactivated by creating a new file with a .mysql extension. A new template lets you create files withthis file type using the Visual Studio 2010 main menu item File, New. Note that the MySQL SQLEditor is also available in Visual Studio 2005 and 2008.

  • Making a Connection

    15

    Visual Studio 2005 is supported only through MySQL Connector/Net 6.4.

    MySQL Connector/Net 6.6 and earlier does not support Express versions of Microsoft developmentproducts, including the Visual Studio and the Microsoft Visual Web Developer.

    MySQL for Visual Studio does not support Express versions of Microsoft development products,including the Visual Studio and the Microsoft Visual Web Developer.

    To use MySQL Connector/Net with an Express versions of Microsoft development products, useMySQL Connector/Net 6.7.4 or later, without installing the MySQL for Visual Studio.

    Up till Connector/Net 6.6, the Visual Studio Plugin is part of the main Connector/Net package and isautomatically installed together with MySQL Connector/Net. The old Visual Studio Plugin release notescan be found here.

    4.2 Making a ConnectionOnce the connector is installed, you can use it to create, modify, and delete connections to MySQLdatabases. To create a connection with a MySQL database, perform the following steps:

    Start Visual Studio, and open the Server Explorer window (View, Server Explorer option in the mainVisual Studio menu, or Control+W, L keyboard shortcuts).

    Right-click the Data Connections node, and choose the Add Connection... menu item.

    Add Connection dialog opens. Press the Change button to choose MySQL Database as a datasource.

    Figure 4.1 Add Connection Context Menu

    Change Data Source dialog opens. Choose MySQL Database in the list of data sources (or the option, if MySQL Database is absent), and then choose .NET Framework Data Providerfor MySQL in the combo box of data providers.Figure 4.2 Choose Data Source

  • Making a Connection

    16

    Input the connection settings: the server host name (for example, localhost if the MySQL server isinstalled on the local machine), the user name, the password, and the default schema name. Notethat you must specify the default schema name to open the connection.

    Figure 4.3 Add Connection Dialog

    You can also set the port to connect with the MySQL server by pressing the Advanced button. Totest connection with the MySQL server, set the server host name, the user name, and the password,and press the Test Connection button. If the test succeeds, the success confirmation dialog opens.

    After you set all settings and test the connection, press OK. The newly created connection isdisplayed in Server Explorer. Now you can work with the MySQL server through standard ServerExplorer GUI.

    Figure 4.4 New Data Connection

  • The MySQL Toolbar

    17

    After the connection is successfully established, all settings are saved for future use. When you startVisual Studio for the next time, open the connection node in Server Explorer to establish a connectionto the MySQL server again.

    To modify and delete a connection, use the Server Explorer context menu for the corresponding node.You can modify any of the settings by overwriting the existing values with new ones. Note that theconnection may be modified or deleted only if no active editor for its objects is opened: otherwise, youmay lose your data.

    4.3 The MySQL ToolbarThe optional MySQL toolbar includes MySQL specific functionality, and links to external MySQL toolssuch as MySQL Workbench and MySQL Utilities.

    Note

    The MySQL toolbar was added in MySQL for Visual Studio 1.1.4.

    After installing MySQL for Visual Studio, the MySQL toolbar is available by selecting from the mainmenu View, Toolbars, MySQL. This is how the MySQL toolbar looks like:

    Figure 4.5 The MySQL for Visual Studio Toolbar

    The MySQL toolbar provides shortcuts to some of the main functionalities of MySQL for Visual Studio:

    MySQL Script Window: Opens a new MySQL script window using the selected connection. Allavailable MySQL connections are listed in a submenu, which can be selected on the toolbar:

  • Using IntelliSense in the SQL Editor

    18

    Figure 4.6 The MySQL for Visual Studio Toolbar: Connections

    The MySQL script window supports the IntelliSense feature for easing MySQL script creation insideVisual Studio.

    Debug MySQL Routine: Starts a debugging session on a selected MySQL stored routine insideVisual Studio.

    MySQL Data Export Tool: Opens a new tabbed-window of the Data Export tool.

    MySQL Workbench SQL Editor: Opens a new Workbench with an SQL editor window using thecurrent MySQL connection, if MySQL Workbench has been installed.

    MySQL Utilities Console: Opens a new console window for the MySQL Utilities tool, if it has beeninstalled.

    4.4 Using IntelliSense in the SQL EditorOnce you have established a connection, for example, using the Connect to MySQL toolbar button, youcan get auto-completion as you type, or by pressing Control + J. Depending on the context, the auto-completion dialog can show the list of available tables, table columns, or stored procedures (with theroutine's signature as a tooltip). Typing some characters before pressing Control + J filters the choicesto those items starting with that prefix.

    Note

    IntelliSense support is available as of MySQL Connector/Net 6.5.

    4.5 Editing TablesConnector/Net contains a table editor, which enables the visual creation and modification of tables.

    The Table Designer can be accessed through a mouse action on table-type node of Server Explorer.To create a new table, right-click the Tables node (under the connection node) and choose the CreateTable command from the context menu.

    To modify an existing table, double-click the node of the table to modify, or right-click this node andchoose the Design item from the context menu. Either of the commands opens the Table Designer.

  • Editing Tables

    19

    Figure 4.7 Editing New Table

    Table Designer consists of the following parts:

    Columns Editor - a data grid on top of the Table Designer. Use the Columns grid for columncreation, modification, and deletion. For additional information, see Section 4.5.1, Column Editor.

    Indexes/Keys window - a window opened from the Table Designer menu to manage indexes.

    Relationships window - a window opened from the Table Designer menu to manage foreign keys.

    Column Properties panel - a panel near the bottom of the Table Designer. Use the ColumnProperties panel to set advanced column options.

    Properties window - a standard Visual Studio Properties window, where the properties of the editedtable are displayed. Use the Properties window to set the table properties. To open, right-click on atable and select the Properties context-menu item.

    Each of these areas is discussed in more detail in subsequent sections.

  • Column Editor

    20

    To save changes you have made in the Table Designer, press either Save or Save All on the VisualStudio main toolbar, or press Control + S. If you have not already named the table, you will beprompted to do so.

    Figure 4.8 Choose Table Name

    Once the table is created, you can view it in the Server Explorer.

    Figure 4.9 Newly Created Table

    The Table Designer main menu lets you set a primary key column, edit relationships such as foreignkeys, and create indexes.

    Figure 4.10 Table Designer Main Menu

    4.5.1 Column EditorYou can use the Column Editor to set or change the name, data type, default value, and otherproperties of a table column. To set the focus to a needed cell of a grid, use the mouse click. Also youcan move through the grid using Tab and Shift + Tab keys.

    To set or change the name, data type, default value and comment of a column, activate the appropriatecell and type the desired value.

    To set or unset flag-type column properties (NOT NULL, auto incremented, flags), select or deselect thecorresponding check boxes. Note that the set of column flags depends on its data type.

    To reorder columns, index columns or foreign key columns in the Column Editor, select the wholecolumn to reorder by clicking the selector column on the left of the column grid. Then move the columnby using Control+Up (to move the column up) or Control+Down (to move the column down) keys.

  • Editing Indexes

    21

    To delete a column, select it by clicking the selector column on the left of the column grid, then pressthe Delete button on a keyboard.

    4.5.2 Editing IndexesIndexes management is performed using the Indexes/Keys dialog.

    To add an index, select Table Designer, Indexes/Keys... from the main menu, and click Add to add anew index. You can then set the index name, index kind, index type, and a set of index columns.

    Figure 4.11 Indexes/Keys Dialog

    To remove an index, select it in the list box on the left, and click the Delete button.

    To change index settings, select the needed index in the list box on the left. The detailed informationabout the index is displayed in the panel on the right hand side. Change the desired values.

    4.5.3 Editing Foreign KeysYou manage foreign keys for InnoDB tables using the Foreign Key Relationships dialog.

    To add a foreign key, select Table Designer, Relationships... from the main menu. This displays theForeign Key Relationship dialog. Click Add. You can then set the foreign key name, referenced tablename, foreign key columns, and actions upon update and delete.

    To remove a foreign key, select it in the list box on the left, and click the Delete button.

    To change foreign key settings, select the required foreign key in the list box on the left. The detailedinformation about the foreign key is displayed in the right hand panel. Change the desired values.

  • Column Properties

    22

    Figure 4.12 Foreign Key Relationships Dialog

    4.5.4 Column PropertiesThe Column Properties tab can be used to set column options. In addition to the general columnproperties presented in the Column Editor, in the Column Properties tab you can set additionalproperties such as Character Set, Collation and Precision.

  • Table Properties

    23

    Figure 4.13 Column Properties Panel

    4.5.5 Table PropertiesTo bring up Table Properties select the table and right-click to activate the context menu. SelectProperties. The Table Properties dockable window will be displayed.

  • Table Properties

    24

    Figure 4.14 Table Properties Panel

    The following table properties are listed under table properties, and many are fully described in theSHOW TABLE STATUS MySQL documentation.

    Auto Increment: The next AUTO_INCREMENT value.

    Average Row Length: The AVG_ROW_LENGTH value.

    Character Set: The Charset value.

    Collation: The Collation value.

    Comment: Table comments.

    Data Directory: The directory used to store data files for this table.

    Index Directory: The directory used to store index files for this table.

    Maximum Rows: Value of the MAX_ROWS property.

    Minimum Rows: Value of the MIN_ROWS property.

    Name: Name of the table.

    Row Format: The ROW_FORMAT value.

    Schema: The schema this table belongs to.

    Storage Engine.

  • Editing Views

    25

    Note

    In MySQL 5.5 and higher, the default storage engine for new tables isInnoDB. See InnoDB as the Default MySQL Storage Engine for moreinformation about the choice of storage engine, and considerations whenconverting existing tables to InnoDB.

    The property Schema is read-only.

    Figure 4.15 Table Properties

    4.6 Editing ViewsTo create a new view, right-click the Views node under the connection node in Server Explorer. Fromthe node's context menu, choose the Create View command. This command opens the SQL Editor.

  • Editing Views

    26

    Figure 4.16 Editing View SQL

    You can then enter the SQL for your view, and then execute the statement.

    To modify an existing view, double-click a node of the view to modify, or right-click this node andchoose the Alter View command from a context menu. Either of the commands opens the SQL Editor.

    All other view properties can be set in the Properties window. These properties are:

    Catalog: The TABLE_CATALOG.

    Check Option: Whether or not the WITH CHECK OPTION clause is present. For additionalinformation, see The View WITH CHECK OPTION Clause.

    Definer: Creator of the object. Definition: Definition of the view.

    Is Updatable: Whether or not the view is Updatable. For additional information, see Updatable andInsertable Views.

    Name: The name of the view.

    Schema: The schema which owns the view.

    Security Type: The SQL SECURITY value. For additional information, see Access Control for StoredPrograms and Views.

    Some of these properties can have arbitrary text values, others accept values from a predefined set. Inthe latter case, set the desired value with an embedded combobox.

    The properties Is Updatable and Schema are read-only.

    To save changes you have made, use either Save or Save All buttons of the Visual Studio maintoolbar, or press Control + S.

  • Editing Stored Procedures and Functions

    27

    Figure 4.17 View SQL Saved

    4.7 Editing Stored Procedures and FunctionsTo create a new stored procedure, right-click the Stored Procedures node under the connectionnode in Server Explorer. From the node's context menu, choose the Create Routine command. Thiscommand opens the SQL Editor.

  • Editing Stored Procedures and Functions

    28

    Figure 4.18 Edit Stored Procedure SQL

    To create a new stored function, right-click the Functions node under the connection node in ServerExplorer. From the node's context menu, choose the Create Routine command.

    To modify an existing stored routine (procedure or function), double-click the node of the routine tomodify, or right-click this node and choose the Alter Routine command from the context menu. Eitherof the commands opens the SQL Editor.

    Routine properties can be viewed in the Properties window. These properties are:

    Body

    Catalog

    Comment

    Creation Time

    Data Access

    Definer

    Definition

    External Name

    External Language

    Is Deterministic

    Last Modified

    Name

    Parameter Style

    Returns

    Schema

    Security Type

  • Editing Triggers

    29

    Specific Name

    SQL Mode

    SQL Path

    Type

    Some of these properties can have arbitrary text values, others accept values from a predefined set. Inboth cases, these values cannot be set from the properties panel.

    You can also set all the options directly in the SQL Editor, using the standard CREATE PROCEDURE orCREATE FUNCTION statement.

    To save changes you have made, use either Save or Save All buttons of the Visual Studio maintoolbar, or press Control + S.

    Figure 4.19 Stored Procedure SQL Saved

    To observe the runtime behavior of a stored routine and debug any problems, use the StoredProcedure Debugger. For additional information, see Section 4.9, Debugging Stored Procedures andFunctions.

    4.8 Editing TriggersTo create a new trigger, right-click the node of the table in which to add the trigger. From the node'scontext menu, choose the Create Trigger command. This command opens the SQL Editor.

    To modify an existing trigger, double-click the node of the trigger to modify, or right-click this node andchoose the Alter Trigger command from the context menu. Either of the commands opens the SQLEditor.

    To create or alter the trigger definition using SQL Editor, type the trigger statement in the SQL Editorusing standard SQL.

  • Debugging Stored Procedures and Functions

    30

    Note

    Enter only the trigger statement, that is, the part of the CREATE TRIGGER querythat is placed after the FOR EACH ROW clause.

    All other trigger properties are set in the Properties window. These properties are:

    Definer

    Event Manipulation

    Name

    Timing

    Some of these properties can have arbitrary text values, others accept values from a predefined set. Inthe latter case, set the desired value using the embedded combo box.

    The properties Event Table, Schema, and Server in the Properties window are read-only.

    To save changes you have made, use either Save or Save All buttons of the Visual Studio maintoolbar, or press Control + S. Before changes are saved, you will be asked to confirm the execution ofthe corresponding SQL query in a confirmation dialog.

    To observe the runtime behavior of a stored routine and debug any problems, use the StoredProcedure Debugger. For additional information, see Section 4.9, Debugging Stored Procedures andFunctions.

    4.9 Debugging Stored Procedures and FunctionsThe stored procedure debugger, provides facilities for setting breakpoints, stepping into individualstatements (Step Into, Step Out, Step Over), evaluating and changing local variable values, evaluatingbreakpoints, and other typical debugging tasks.

    Note

    This feature is available as of MySQL Connector/Net 6.6.

    Installing the DebuggerTo enable the stored procedure debugger:

    For Connector/Net 6.6: Install Connector/Net 6.6 and choose the Complete option.

    For Connector/Net 6.7 and later: Install the product MySQL for Visual Studio, to which the storedprocedure debugger belongs.

    PrivilegesThe debugger recreates at the start of each debug session a serversidedebugger database in yourserver. This database helps to track the instrumented code and implement observability logic in thedebugged routine. Your current connection needs to have privileges to create that database, and itsassociated stored routines, functions, and tables.

    The debugger makes changes behind the scenes to temporarily add instrumentation code to the storedroutines that you debug. You must have the ALTER ROUTINE privilege for each stored procedure,function, or trigger that you debug. (Including procedures and functions that are called, and triggers thatare fired, by a procedure that you are debugging.)

    Starting the DebuggerTo start the debugger, follow these steps:

  • Starting the Debugger

    31

    Choose a connection in the Visual Studio Server Explorer.

    Expand the Stored Procedures folder. Only stored procedures can be debugged directly. Todebug a user-defined function, create a stored procedure that calls the function.

    Click on a stored procedure node, then right-click and from the context menu choose DebugRoutine.

    Figure 4.20 Choose a Stored Routine to Debug

    At this point, Visual Studio switches to debug mode, opening the source code of the routine beingdebugged in step mode, positioned on the first statement.

    If the initial routine you debug has one or more arguments, a pop-up will show up with a grid (a row pereach argument and three columns: one for the argument, one for the argument value (this is editable)and one for nullifying that argument value (a checkbox)). After setting up all the argument values, youcan press OK to start the debug session, or Cancel to cancel the debug session.

    Figure 4.21 Setting Arguments (1 of 2)

  • How the Debugger Works

    32

    Figure 4.22 Setting Arguments (2 of 2)

    How the Debugger WorksTo have visibility into the internal workings of a stored routine, the debugger prepares a special versionof the procedure, function, or trigger being debugged, instrumented with extra code to keep track of thecurrent line being stepped into and the values of all the local variables. Any other stored procedures,functions, or triggers called from the routine being debugged are instrumented the same way. Thedebug versions of the routines are prepared for you automatically, and when the debug session ends(by either pressing F5 or Shift + F5), the original versions of the routines are automatically restored.A copy of the original version of each instrumented routine (the version withoutinstrumentation) is stored in the AppData\Roaming\MySqlDebuggerCachefolder for the current Windows user (the path returned by callingSystem.Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)in .NET, plus appending MySqlDebuggerCache. There is one file for each instrumented routine,named routine_name.mysql. For example, in Windows 7, for a user named fergs, the path is C:\Users\fergs\AppData\Roaming\MySqlDebuggerCache.

    Two threads are used, one for the debugger and one for the routine being debugged. The threads runin strict alternation, switching between the debugger and the routine as each statement is executed inthe stored routine.

    Basic Debugging OperationsThe debugger has the same look and feel as the standard Visual Studio debuggers for C#, VB.NET orC++. In particular, the following are true:

    Locals and Watches

    To show the Locals tab, choose the menu item Debug, Windows, Locals.

  • Basic Debugging Operations

    33

    The Locals tab lists all the variables available in the current scope: variables defined with DECLAREat any point in the routine, argument parameters, and session variables that are referenced.

    If the last step operation changes the value of a local, its value will be highlighted in red (until anotherstatement is executed or stepped.

    You can change the value of any local.

    To show the Watch tab, choose the menu item Debug, Windows, Watch.

    To define a watch, type any valid MySQL expression, optionally including function calls. If the watchevaluation makes sense in the current context (current stack frame), it will show its value, otherwiseit will show an error message in the same row the watch was defined.

    When debugging a trigger, in addition to any locals declared or session variables referenced, thenew and old object (when applicable) will be listed. For example in a trigger for INSERT, for a tabledefined like:

    create table t1( id int, myname varchar( 50 ));

    the locals will list the extra variables new.id and new.myname. For an UPDATE trigger, you will alsoget the extra variables old.id and old.myname. These variables from the new and old objects canbe manipulated the same way as any ordinary local variable.

    Figure 4.23 Debugging a Trigger

    Call Stack

    To show the Call Stack tab, choose the menu item Debug, Windows, Call Stack.

  • Basic Debugging Operations

    34

    The stack trace (in the Call Stack tab) will list all the stack traces, one for each routine invocation.The one with a yellow mark is the current stepping point. Clicking in another will activate in the editorthe tab for that routine source, highlighting in green the last statement stepped.

    Figure 4.24 Call Stack

    Stepping

    Stepping of a new routine starts in the first executable instruction (excluding declares, handlers,cursor declarations, and so on).

  • Basic Debugging Operations

    35

    Figure 4.25 Debug Stepping

    Figure 4.26 Function Stepping (1 of 2)

  • Basic Debugging Operations

    36

    Figure 4.27 Function Stepping (2 of 2)

    To step into the code of a condition handler, the condition must be triggered in the rest of the MySQLroutine.

    The next statement to be executed is highlighted in yellow.

    To continue stepping, you can choose between Step Into (by pressing F11), Step Out (by pressingF10) or Step Over (by pressing Shift + F11).

    You can step out of any of functions, triggers or stored procedures. If you step from the main routine,it will run that routine to completion and finish the debug session.

    You can step over stored procedure calls, stored functions, and triggers. (To step over a trigger, stepover the statement that would cause the trigger to fire.)

    When stepping into a single statement, the debugger will step into each individual function invokedby that statement and each trigger fired by that statement. The order in which they are debugged isthe same order in which the MySQL server executes them.

    You can step into triggers triggered from INSERT, DELETE, UPDATE, and REPLACE statements.

    Also, the number of times you enter into a stored function or trigger depends on how many rowsare evaluated by the function or affected by the trigger. For example, if you press F11 (Step Into)into an UPDATE statement that modifies three rows (calling a function for a column in the SETclause, thus invoking the function for each of the three rows), you will step into that function threetimes in succession, once for each of the rows. You can accelerate this debug session by disablingany breakpoints defined in the given stored function and pressing Shift + F11 to step out. In thisexample, the order in which the different instances of the stored function are debugged is server-specific: the same order used by the current MySQL server instance to evaluate the three functioninvocations.

    Breakpoints

  • Basic Debugging Operations

    37

    To show the Breakpoints tab, choose the menu item Debug, Windows, Breakpoints.

    The Breakpoints tab will show all the breakpoints defined. From here, you can enable and disablebreakpoints one by one or all at once (using the toolbar on top of the Breakpoints tab).

    You can define new breakpoints only in the middle of a debug session. Click in the left gray borderof any MySQL editor, or click anywhere in a MySQL editor and press F9. In the familiar VisualStudio way, you press F9 once to create a breakpoint in that line, and press it again to remove thatbreakpoint.

    Once a breakpoint is defined, it will appear enabled (as filled red circle left to the current row if thatline is a valid statement to put a breakpoint) or disabled (as a non-filled red circle left to the currentrow if that row is not valid to put a breakpoint).

    To define conditional breakpoints, after creating the breakpoint, right click in the red dot and chooseCondition.... There you can put any valid MySQL expression and state if the condition is Is True orHas changed. The former will trigger the breakpoint every time the condition is true, the latter everytime the condition value has changed. (If you define a conditional breakpoint, it is not enough to stepinto the line with the breakpoint defined to trigger such a breakpoint.)

    Figure 4.28 Conditional Breakpoints

  • Other Features

    38

    Figure 4.29 Expressions and Breakpoints

    To define pass count breakpoints, after creating the breakpoint, right click in the red dot and chooseHit Count.... In the pop-up dialog, define the specific condition to set. For example, break when thehit count is equal to and a value 3 will trigger the breakpoint the third time it is hit.

    Other Features To abort the debug session (and the execution of the current call stack of routines), press Shift + F5. To run the routine to completion (or until next breakpoint hit), press F5. For all functionality you can use (in addition to the shortcuts documented), see the options in the

    Debug menu of Visual Studio.

    Limitations Code being debugged must not use get_lock or release_lock MySQL functions, since they

    are used internally by the debugger infrastructure to synchronize the debugger and the debuggedroutine.

    Code being debugged must avoid using any transaction code (START TRANSACTION, COMMIT,ROLLBACK) due to the possibility of wiping out the contents of the debugger tables. (This limitationmay be removed in the future).

    You cannot debug the routines in the serversidedebugger database.

    The MySQL server running the routine being debugged can be any MySQL server version after 5.0,and running on any supported platform.

    We recommend always running debug sessions on test and development servers, rather thanagainst a MySQL production server, because debugging can cause temporary performance issuesor even deadlocks. The instrumented versions of the routines being debugged use locks, that therest of the production code may not be aware of.

  • Keyboard Shortcuts

    39

    Keyboard ShortcutsThe following list summarizes the keyboard shortcuts for debugging:

    F9 Toggles breakpoints

    F11: Step into once

    F10: Step over once

    Shift + F11: Step out once

    F5: Run

    Shift + F5: Abort current debug session

    4.10 Deleting Database ObjectsTables, views, stored routines, and triggers can be dropped with the appropriate Delete commandselected from its context menu.

    You will be asked to confirm the execution of the corresponding drop query in a confirmation dialog.

    You can only drop a single object at a time.

    4.11 Using the ADO.NET Entity FrameworkADO.NET Entity Framework was included with .NET Framework 3.5 Service Pack 1, and Visual Studio2008 Service Pack 1. ADO.NET Entity Framework was released on 11th August 2008.

    Note

    The ADO.NET Entity Framework is supported as of MySQL Connector/Net6.0.0.

    ADO.NET Entity Framework provides an Object Relational Mapping (ORM) service, mapping therelational database schema to objects. The ADO.NET Entity Framework defines several layers, thesecan be summarized as:

    Logical - this layer defines the relational data and is defined by the Store Schema DefinitionLanguage (SSDL).

    Conceptual - this layer defines the .NET classes and is defined by the Conceptual SchemaDefinition Language (CSDL)

    Mapping - this layer defines the mapping from .NET classes to relational tables and associations,and is defined by Mapping Specification Language (MSL).

    Connector/Net integrates with Visual Studio 2008 (and later) to provide a range of helpful tools to assistthe developer.

    A full treatment of ADO.NET Entity Framework is beyond the scope of this manual. If you are unfamiliarwith ADO.NET, review the Microsoft ADO.NET Entity Framework documentation.

    Tutorials on getting started with ADO.NET Entity Framework are available. See Section 5.7, Tutorial:Using an Entity Framework Entity as a Windows Forms Data Source and Section 5.8, Tutorial:Databinding in ASP.NET Using LINQ on Entities.

    4.12 MySQL Website Configuration Tool

  • MySQL Website Configuration Tool

    40

    This MySQL for Visual Studio feature enables you to configure the Membership, Role, Site Map,Personalization, Session State, and Profile Provider options without editing the configuration files. Youset your configuration options within the tool, and the tool modifies your web.config file accordingly.

    Note

    Site Map and Personalization provider support requires Connector/Net 6.9.2 orlater, and MySQL for Visual Studio 1.2.1 or later.

    The MySQL Website Configuration Tool appears as a small icon on the Solution Explorer toolbar inVisual Studio, as show by the following screenshot:

    Figure 4.30 MySQL Website Configuration Tool

    Note

    The MySQL Website Configuration Tool icon is only visible if a MySQL project isactive.

    Clicking the Website Configuration Tool icon launches the wizard and displays the first screen:

  • Advanced Membership Provider

    41

    Figure 4.31 MySQL Website Configuration Tool - Membership

    This allows you to enable a MySQL Membership Provider. In addition to the standard (advanced)"Membership" provider, there is also a "Simple Membership" provider. You can only choose one ofthese two membership providers.

    Advanced Membership ProviderTo use the more advanced "Membership" provider, select the "Use MySQL to manage my membershiprecords check box to enable this. You can now enter the name of the application that you are creatingthe configuration for. You can also enter a description for the application.

    You can then click the Edit... button to launch the Connection String Editor:

  • Advanced Membership Provider

    42

    Figure 4.32 MySQL Website Configuration Tool - Connection String Editor

    Note

    Defined connection strings are automatically loaded and available in this dialog,whether they were created manually in web.config or previously using thistool.

    You can also ensure that the necessary schemas are created automatically for you by selecting theAutogenerate Schema check box. These schemas are used to store membership information. Thedatabase used to storage is the one specified in the connection string.

    You can also ensure that exceptions generated by the application will be written to the Windows eventlog by selecting the Write exceptions to event log check box.

    Clicking the Advanced... button launches a dialog that enables you to set Membership Options.These options dictate such variables as password length required when a user signs up, whether thepassword is encrypted and whether the user can reset their password or not.

  • Simple Membership Provider

    43

    Figure 4.33 MySQL Website Configuration Tool - Advanced Options

    Simple Membership ProviderThe "Simple Membership" provider is similar to the advanced version, but it includes less options. Toenable, check the "Use MySQL to manage my simple membership records" check box.

    Note

    The "Simple Membership" option was added in MySQL for Visual Studio version1.2.3.

    Figure 4.34 MySQL Website Configuration Tool - Simple Membership

    The MySQL Simple Membership provider handles the web site membership tasks with ASP.NET. Thisprovider is a simpler version of the ASP.NET Membership provider, and it can also work with OAuth

  • Simple Membership Provider

    44

    Authentication. For additional information about using OAuth authentication, see Section 5.6.3, AddingOAuth Authentication to a Project.The required configuration options for the Simple Membership provider are: a name for the connectionstring, and a connection string that contains a valid database with a local or remote MySQL serverinstance, a user table to store the credentials, and column names for the User ID and User Namecolumns.

    Check the Auto Create Tables option to create the required tables when adding the first user to thetable.

    After setting up a membership provider, a new section is added to the web configuration file.

    Figure 4.35 MySQL Website Configuration Tool - Simple Membership Entry

    After setting up one of the membership providers, click Next to configure the Roles Provider:

    Figure 4.36 MySQL Website Configuration Tool - Roles

    Again the connection string can be edited, a description added and Autogenerate Schema can beenabled before clicking Next to go to the Profiles Provider screen:

  • Simple Membership Provider

    45

    Figure 4.37 MySQL Website Configuration Tool - Profiles

    This screen display similar options to the previous screens.

    Click Next to proceed to the Session State configuration page:

    Figure 4.38 MySQL Website Configuration Tool - Session State

    Click Next to proceed to the Site Map configuration page:

  • Simple Membership Provider

    46

    Figure 4.39 MySQL Website Configuration Tool - Site Map

    The Site Map provider builds a site map from a MySQL database, and builds a complete tree of theSitemapNode objects. It also provides methods so that the generated nodes can be read from the sitemap.

    The required configuration options: A name for the connection string, and a connection string thatcontains a valid database with a local or remote MySQL server instance.

    After setting up the Site Map provider, a new section is added to the web configuration file.

    Figure 4.40 MySQL Website Configuration Tool - Site Map, Configuration Entry

    Click Next to proceed to the Web Personalization configuration page:

  • Simple Membership Provider

    47

    Figure 4.41 MySQL Website Configuration Tool - Web Personalization

    The Web Personalization provider is used when a Web Site application needs to store persistentinformation for the content and layout of the Web Parts pages that are generated by a Web Partspersonalization service. This provider should be used along with the Membership, Roles, and Profilesproviders.

    The required configuration options: A name for the connection string, and a connection string thatcontains a valid database with a local or remote MySQL server instance.

    After setting up the Personalization provider, a new section is added to the web configuration file.

    Figure 4.42 MySQL Website Configuration Tool - Web Personalization, Configuration Entry

    Once you have set up the optional Web Personalization options, click Finish to exit the wizard.

    At this point, select the Authentication Type to From Internet. Launch the WEBSITE, ASP.NETConfiguration tool and select the Security tab. Click the Select authentication type link and ensurethat the From the internet radio button is selected. You can now examine the database you created tostore membership information. All the necessary tables will have been created for you:

  • Windows Forms Project Wizard

    48

    Figure 4.43 MySQL Website Configuration Tool - Tables

    For users of Visual Studio 2010 and earlier who want to perform the configuration by editing theweb.config file manually (recommended only for advanced users), the following pages provide someuseful info:

    Section 6.20, ASP.NET Provider Model

    Section 5.3, Tutorial: MySQL Connector/Net ASP.NET Session State Provider

    Section 5.4, Tutorial: MySQL Connector/Net ASP.NET Profile Provider

    4.13 Windows Forms Project WizardIntroduction

    This wizard automates the generation of a simple .NET Windows Forms Application with CRUD pagesthat are connected to a MySQL data source. The generated application includes:

    Generates individual controls, with or without validation.

    Master Detail and Grid layouts using a Typed Dataset data source, or with Entity Framework version5 or 6, depending on your selection.

    This wizard can create an application with either the C# or Visual Basic programming languages.

    4.13.1 Requirements MySQL for Visual Studio 1.2.1 or greater.

    Connector/NET 6.7 or greater installed on the system, for execution.

    The wizard can be executed without having Connector/Net installed, but it is necessary to have aConnector/Net installed to execute the generated Windows Forms application.

    Visual Studio 2010 or later, and the professional edition or greater.

    Entity Framework 6 is only available in Visual Studio 2013 and greater, and this option will appeardisabled for other Visual Studio versions.

    4.13.2 Usage: Creating A New Windows Forms ApplicationTo begin creating a new Windows Forms Project, you can either:

  • Usage: Creating A New Windows Forms Application

    49

    Click File from the main navigation menu, and then select New Project. From the MySQL toolbar inside Visual Studio. To enable the toolbar, select View from the main

    navigation menu, and choose MySQL from the Toolbar menu.

    From the MySQL toolbar, click the New Project button to open the Create new MySQL projectwizard.

    Figure 4.44 Creating a New Windows Form Project from the MySQL Toolbar

    Figure 4.45 Creating a New Windows Form Project from the Project Selector

    Step one -- Select the database connection for web authentication:

    First, set up a connection to your MySQL Database.

  • Usage: Creating A New Windows Forms Application

    50

    Figure 4.46 Windows Forms Project: Data Source Configuration

    The data source configuration step allows you to customize the connection and database for yourapplication. The connection string can be selected from the dropdown list, or a new connection can beset up by clicking New Connection .

    After the MySQL connection is set up and selected, the connection string is listed for review. While thewizard can generate a MySQL connection string that includes your credentials, this insecure practice isnot recommended because the credentials would be shown as plain text in the web configuration file.

    In addition to the data connection, you must also define the data access technology used to connectyour database with the forms that the wizard will generate. You can choose between three options:

    Typed Dataset: Generates a typed dataset with TableAdapters

    Entity Framework version 5.0: Database First, based on ObjectContext

    Entity Framework version 6.0: Database First, based on DbContext

    Step two -- Database objects selection:

    Now, a list of tables from your selected database is listed. Select the tables used by your application.

    Every table represents a Form in your application. In the grid, the Customize column contains buttonsthat trigger their own wizard that helps you select the layout for the generated form for the individualtables.

  • Usage: Creating A New Windows Forms Application

    51

    Figure 4.47 Windows Forms Project: Database objects selection

    There are three types of views (layouts) that you can select from when customizing the forms: Single column (default): each column of the table can be edited with an input textbox, with the

    following exceptions:

    Datetime types are entered with DateTimePicker control.

    Boolean types are entered with a checkbox control.

    Note

    This follows the standard rule of Connector/NET and its Entity Frameworkprovider. When treated as booleans, these columns (which aretinyint(1), bit, bool, or boolean) have the default connection string settingTreatTinyIntAsBoolean=True.

    Foreign Keys, can optionally be rendered as Lookup ComboBox control.

    Note

    A lookup combobox is a combobox (or drop down list) that displays a listof friendly values for the user, but internally they translate to numeric ID,which is more efficient for the database. For example, it is possible for the"sakila.customer" table to render a lookup Combobox