MySQL Connector/NET Developer Guide









ASP.NET Core - Connection String

the database. • In this tutorial we will use SQL Server Visual. Studio
ASP.NET Core Connection String


ASP.NET Core Database Communication

ASP.NET Core. Database Communication. Hans-Petter Halvorsen NET Core I suggest the ... SqlConnection con = new SqlConnection(connectionString);.
ASP.NET Core Database Communication


SAP HANA Client Interface Programming Reference

20 Apr 2021 NET Core have separate SAP HANA providers in the ... For hdbsql connections the connection string must either explicitly reference the ...
SAP HANA Client Interface Programming Reference en


TIBCO Data Virtualization Client Interfaces Guide

15 Jul 2020 Example Java JDBC Client Application Code . ... Connection String Options . ... NET Connection to a Client Restricted Server .
TIB tdv . . ClientInterfacesGuide ?id=





MySQL Connector/NET Developer Guide

string see Section 4.5
connector net en


MySQL Connector/NET Developer Guide

string see Section 4.5
connector net en.a


Web Programming - ASP.NET Core

NET Core. Preface. This textbook gives an overview of Web and Web programming in Inside “ConnectionStrings” you can have one or more connection strings ...
Web Programming ASP.NET Core


MySQL Connector/NET Release Notes

Changes in MySQL Connector/NET 6.10.5 (2017-12-08 General Availability) . string (or ConnectionString property) now is removed. Currently
connector net relnotes en





ASP.NET Core - User Identity and Login

ASP.NET Core. User Identity and Login. Hans-Petter Halvorsen NET Core I suggest the ... using (SqlConnection con = new SqlConnection(connectionString)).
ASP.NET Core User Identity and Login


On-site deployment

NET Core. Deploying Creatio .NET Core application. Deploy Microsoft SQL database for Creatio Modify ConnectionStrings.config for MS SQL Server.


208766 MySQL Connector/NET Developer Guide

MySQL Connector/NET Developer Guide

Abstract

This manual describes how to install and configure MySQL Connector/NET, the connector that enables .NET

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

For legal information, including licensing information, see the Preface and Legal Notices.

For help with using MySQL, please visit the MySQL Forums, where you can discuss your issues with other MySQL

users. Document generated on: 2023-05-29 (revision: 75759)

Table of Contents

Preface and Legal Notices..................................................................................................................v

1 Introduction to MySQL Connector/NET.............................................................................................1

2 Connector/NET Versions.................................................................................................................3

3 Connector/NET Installation..............................................................................................................9

3.1 Installing Connector/NET on Windows...................................................................................9

3.1.1 Installing Connector/NET Using MySQL Installer.......................................................10

3.1.2 Installing Connector/NET Using the Standalone Installer............................................10

3.1.3 Installing Connector/NET Using NuGet.....................................................................11

3.2 Installing Connector/NET on Unix with Mono.......................................................................12

3.3 Installing Connector/NET from Source.................................................................................13

4 Connector/NET Connections..........................................................................................................15

4.1 Creating a Connector/NET Connection String......................................................................15

4.2 Managing a Connection Pool in Connector/NET...................................................................18

4.3 Handling Connection Errors................................................................................................19

4.4 Connector/NET Authentication.............................................................................................20

4.5 Connector/NET Connection Options Reference....................................................................25

5 Connector/NET Programming........................................................................................................43

5.1 Using GetSchema on a Connection.....................................................................................44

5.2 Using MySqlCommand.......................................................................................................46

5.3 Using Connector/NET with Table Caching...........................................................................49

5.4 Preparing Statements in Connector/NET..............................................................................49

5.5 Creating and Calling Stored Procedures..............................................................................50

5.6 Handling BLOB Data With Connector/NET...........................................................................54

5.6.1 Preparing the MySQL Server...................................................................................55

5.6.2 Writing a File to the Database..................................................................................55

5.6.3 Reading a BLOB from the Database to a File on Disk...............................................57

5.7 Working with Partial Trust / Medium Trust............................................................................58

5.7.1 Evolution of Partial Trust Support Across Connector/NET Versions.............................59

5.7.2 Configuring Partial Trust with Connector/NET Library Installed in GAC........................59

5.7.3 Configuring Partial Trust with Connector/NET Library Not Installed in GAC..................61

5.8 Writing a Custom Authentication Plugin...............................................................................62

5.9 Using the Connector/NET Interceptor Classes.....................................................................65

5.10 Handling Date and Time Information in Connector/NET......................................................67

5.10.1 Fractional Seconds................................................................................................67

5.10.2 Problems when Using Invalid Dates........................................................................67

5.10.3 Restricting Invalid Dates.........................................................................................67

5.10.4 Handling Invalid Dates...........................................................................................68

5.10.5 Handling NULL Dates............................................................................................68

5.11 Using the MySqlBulkLoader Class.....................................................................................69

5.12 Using the Connector/NET Trace Source Object..................................................................70

5.12.1 Viewing MySQL Trace Information..........................................................................71

5.12.2 Building Custom Listeners......................................................................................74

5.13 Using Connector/NET with Crystal Reports........................................................................75

5.13.1 Creating a Data Source..........................................................................................75

5.13.2 Creating the Report................................................................................................76

5.13.3 Displaying the Report.............................................................................................77

5.14 Asynchronous Methods.....................................................................................................80

5.15 Binary and Nonbinary Issues.............................................................................................86

5.16 Character Set Considerations for Connector/NET...............................................................87

6 Connector/NET Tutorials................................................................................................................89

6.1 Tutorial: An Introduction to Connector/NET Programming.....................................................89

iii

MySQL Connector/NET Developer Guide6.1.1 The MySqlConnection Object...................................................................................89

6.1.2 The MySqlCommand Object.....................................................................................90

6.1.3 Working with Decoupled Data..................................................................................93

6.1.4 Working with Parameters.........................................................................................96

6.1.5 Working with Stored Procedures...............................................................................97

6.2 ASP.NET Provider Model and Tutorials...............................................................................99

6.2.1 Tutorial: Connector/NET ASP.NET Membership and Role Provider...........................101

6.2.2 Tutorial: Connector/NET ASP.NET Profile Provider..................................................104

6.2.3 Tutorial: Web Parts Personalization Provider...........................................................107

6.2.4 Tutorial: Simple Membership Web Provider.............................................................111

6.3 Tutorial: Using an Entity Framework Entity as a Windows Forms Data Source......................116

6.4 Tutorial: Data Binding in ASP.NET Using LINQ on Entities..................................................124

6.5 Tutorial: Generating MySQL DDL from an Entity Framework Model.....................................127

6.6 Tutorial: Basic CRUD Operations with Connector/NET........................................................128

6.7 Tutorial: Configuring SSL with Connector/NET...................................................................131

6.7.1 Using PEM Certificates in Connector/NET...............................................................132

6.7.2 Using PFX Certificates in Connector/NET................................................................133

6.8 Tutorial: Using MySqlScript...............................................................................................135

7 Connector/NET for Entity Framework...........................................................................................139

7.1 Entity Framework 6 Support..............................................................................................139

7.2 Entity Framework Core Support.........................................................................................145

7.2.1 Creating a Database with Code First in EF Core.....................................................147

7.2.2 Scaffolding an Existing Database in EF Core..........................................................151

7.2.3 Configuring Character Sets and Collations in EF Core.............................................154

8 Connector/NET API Reference.....................................................................................................157

8.1 MySql.Data.Common.DnsClient.........................................................................................157

8.2 MySql.Data.MySqlClient Namespace.................................................................................157

8.3 MySql.Data.MySqlClient.Authentication Namespace...........................................................160

8.4 MySql.Data.MySqlClient.Interceptors Namespace...............................................................161

8.5 MySql.Data.MySqlClient.Replication Namespace................................................................161

8.6 MySql.Data.Types Namespace..........................................................................................161

8.7 MySql.Data.EntityFramework Namespace..........................................................................161

8.8 Microsoft.EntityFrameworkCore Namespace.......................................................................163

8.9 MySql.EntityFrameworkCore Namespace...........................................................................163

8.10 MySql.Web Namespace..................................................................................................165

9 Connector/NET Support...............................................................................................................169

9.1 Connector/NET Community Support..................................................................................169

9.2 How to Report Connector/NET Problems or Bugs..............................................................169

10 Connector/NET FAQ..................................................................................................................171

iv

Preface and Legal Notices

This is the developer guide for MySQL Connector/NET. Licensing information. This product may include third-party software, used under license. MySQL Connector/NET Community License Information User Manual has information about licenses relating to Connector/NET community releases up to and including version 7.0. MySQL Connector/NET Commercial License Information User Manual has information about licenses relating to Connector/NET commercial releases up to and including version 7.0. MySQL Connector/NET 8.0 Community License Information User

Manual has information about licenses relating to Connector/NET community releases in the 8.0 release

series. MySQL Connector/NET 8.0 Commercial License Information User Manual has information about licenses relating to Connector/NET commercial releases in the 8.0 release series.

Legal Notices

Copyright © 2004, 2023, Oracle and/or its affiliates.

This software and related documentation are provided under a license agreement containing restrictions

on use and disclosure and are protected by intellectual property laws. Except as expressly permitted 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 any form, or by any

means. Reverse engineering, disassembly, or decompilation of this software, unless required 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 is software or related documentation that is delivered to the U.S. Government or anyone licensing it

on behalf of the U.S. Government, then the following notice is applicable: U.S. GOVERNMENT END USERS: Oracle programs (including any operating system, integrated software, any programs embedded, installed or activated on delivered hardware, and modifications of such programs) and Oracle computer documentation or other Oracle data delivered to or accessed by U.S. Government end users are "commercial computer software" or "commercial computer software documentation" pursuant to the applicable Federal Acquisition Regulation and agency-specific supplemental regulations. As such, the use, reproduction, duplication, release, display, disclosure,

modification, preparation of derivative works, and/or adaptation of i) Oracle programs (including any

operating system, integrated software, any programs embedded, installed or activated on delivered

hardware, and modifications of such programs), ii) Oracle computer documentation and/or iii) other Oracle

data, is subject to the rights and limitations specified in the license contained in the applicable contract.

The terms governing the U.S. Government's use of Oracle cloud services are defined by the applicable contract for such services. No other rights are granted to the U.S. Government. This software or hardware is developed for general use in a variety of information management

applications. It is not developed or intended for use in any inherently dangerous applications, including

applications that may create a risk of personal injury. If you use this software or hardware in dangerous

applications, then you shall be responsible to take all appropriate fail-safe, backup, redundancy, and other

measures to ensure its safe use. Oracle Corporation and its affiliates disclaim any liability for any damages

caused by use of this software or hardware in dangerous applications.

Oracle, Java, and MySQL are registered trademarks of Oracle and/or its affiliates. Other names may be

trademarks of their respective owners.

Intel and Intel Inside are trademarks or registered trademarks of Intel Corporation. All SPARC trademarks

are used under license and are trademarks or registered trademarks of SPARC International, Inc. AMD, v

Documentation AccessibilityEpyc, and the AMD logo are trademarks or registered trademarks of Advanced Micro Devices. UNIX is a

registered trademark of The Open Group. This software or hardware and documentation may provide access to or information about content,

products, and services from third parties. Oracle Corporation and its affiliates are not responsible for and

expressly disclaim all warranties of any kind with respect to third-party content, products, and services

unless otherwise set forth in an applicable agreement between you and Oracle. Oracle Corporation and its

affiliates will not be responsible for any loss, costs, or damages incurred due to your access to or use of

third-party content, products, or services, except as set forth in an applicable agreement between you and

Oracle.

This documentation is NOT distributed under a GPL license. Use of this documentation is subject to the

following terms:

You may create a printed copy of this documentation solely for your own personal use. Conversion to other

formats is allowed as long as the actual content is not altered or edited in any way. You shall not publish

or distribute this documentation in any form or on any media, except if you distribute the documentation in

a manner similar to how Oracle disseminates it (that is, electronically for download on a Web site with the

software) or on a CD-ROM or similar medium, provided however that the documentation is disseminated together with the software on the same medium. Any other use, such as any dissemination of printed

copies or use of this documentation, in whole or in part, in another publication, requires the prior written

MySQL Connector/NET Developer Guide

Abstract

This manual describes how to install and configure MySQL Connector/NET, the connector that enables .NET

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

For legal information, including licensing information, see the Preface and Legal Notices.

For help with using MySQL, please visit the MySQL Forums, where you can discuss your issues with other MySQL

users. Document generated on: 2023-05-29 (revision: 75759)

Table of Contents

Preface and Legal Notices..................................................................................................................v

1 Introduction to MySQL Connector/NET.............................................................................................1

2 Connector/NET Versions.................................................................................................................3

3 Connector/NET Installation..............................................................................................................9

3.1 Installing Connector/NET on Windows...................................................................................9

3.1.1 Installing Connector/NET Using MySQL Installer.......................................................10

3.1.2 Installing Connector/NET Using the Standalone Installer............................................10

3.1.3 Installing Connector/NET Using NuGet.....................................................................11

3.2 Installing Connector/NET on Unix with Mono.......................................................................12

3.3 Installing Connector/NET from Source.................................................................................13

4 Connector/NET Connections..........................................................................................................15

4.1 Creating a Connector/NET Connection String......................................................................15

4.2 Managing a Connection Pool in Connector/NET...................................................................18

4.3 Handling Connection Errors................................................................................................19

4.4 Connector/NET Authentication.............................................................................................20

4.5 Connector/NET Connection Options Reference....................................................................25

5 Connector/NET Programming........................................................................................................43

5.1 Using GetSchema on a Connection.....................................................................................44

5.2 Using MySqlCommand.......................................................................................................46

5.3 Using Connector/NET with Table Caching...........................................................................49

5.4 Preparing Statements in Connector/NET..............................................................................49

5.5 Creating and Calling Stored Procedures..............................................................................50

5.6 Handling BLOB Data With Connector/NET...........................................................................54

5.6.1 Preparing the MySQL Server...................................................................................55

5.6.2 Writing a File to the Database..................................................................................55

5.6.3 Reading a BLOB from the Database to a File on Disk...............................................57

5.7 Working with Partial Trust / Medium Trust............................................................................58

5.7.1 Evolution of Partial Trust Support Across Connector/NET Versions.............................59

5.7.2 Configuring Partial Trust with Connector/NET Library Installed in GAC........................59

5.7.3 Configuring Partial Trust with Connector/NET Library Not Installed in GAC..................61

5.8 Writing a Custom Authentication Plugin...............................................................................62

5.9 Using the Connector/NET Interceptor Classes.....................................................................65

5.10 Handling Date and Time Information in Connector/NET......................................................67

5.10.1 Fractional Seconds................................................................................................67

5.10.2 Problems when Using Invalid Dates........................................................................67

5.10.3 Restricting Invalid Dates.........................................................................................67

5.10.4 Handling Invalid Dates...........................................................................................68

5.10.5 Handling NULL Dates............................................................................................68

5.11 Using the MySqlBulkLoader Class.....................................................................................69

5.12 Using the Connector/NET Trace Source Object..................................................................70

5.12.1 Viewing MySQL Trace Information..........................................................................71

5.12.2 Building Custom Listeners......................................................................................74

5.13 Using Connector/NET with Crystal Reports........................................................................75

5.13.1 Creating a Data Source..........................................................................................75

5.13.2 Creating the Report................................................................................................76

5.13.3 Displaying the Report.............................................................................................77

5.14 Asynchronous Methods.....................................................................................................80

5.15 Binary and Nonbinary Issues.............................................................................................86

5.16 Character Set Considerations for Connector/NET...............................................................87

6 Connector/NET Tutorials................................................................................................................89

6.1 Tutorial: An Introduction to Connector/NET Programming.....................................................89

iii

MySQL Connector/NET Developer Guide6.1.1 The MySqlConnection Object...................................................................................89

6.1.2 The MySqlCommand Object.....................................................................................90

6.1.3 Working with Decoupled Data..................................................................................93

6.1.4 Working with Parameters.........................................................................................96

6.1.5 Working with Stored Procedures...............................................................................97

6.2 ASP.NET Provider Model and Tutorials...............................................................................99

6.2.1 Tutorial: Connector/NET ASP.NET Membership and Role Provider...........................101

6.2.2 Tutorial: Connector/NET ASP.NET Profile Provider..................................................104

6.2.3 Tutorial: Web Parts Personalization Provider...........................................................107

6.2.4 Tutorial: Simple Membership Web Provider.............................................................111

6.3 Tutorial: Using an Entity Framework Entity as a Windows Forms Data Source......................116

6.4 Tutorial: Data Binding in ASP.NET Using LINQ on Entities..................................................124

6.5 Tutorial: Generating MySQL DDL from an Entity Framework Model.....................................127

6.6 Tutorial: Basic CRUD Operations with Connector/NET........................................................128

6.7 Tutorial: Configuring SSL with Connector/NET...................................................................131

6.7.1 Using PEM Certificates in Connector/NET...............................................................132

6.7.2 Using PFX Certificates in Connector/NET................................................................133

6.8 Tutorial: Using MySqlScript...............................................................................................135

7 Connector/NET for Entity Framework...........................................................................................139

7.1 Entity Framework 6 Support..............................................................................................139

7.2 Entity Framework Core Support.........................................................................................145

7.2.1 Creating a Database with Code First in EF Core.....................................................147

7.2.2 Scaffolding an Existing Database in EF Core..........................................................151

7.2.3 Configuring Character Sets and Collations in EF Core.............................................154

8 Connector/NET API Reference.....................................................................................................157

8.1 MySql.Data.Common.DnsClient.........................................................................................157

8.2 MySql.Data.MySqlClient Namespace.................................................................................157

8.3 MySql.Data.MySqlClient.Authentication Namespace...........................................................160

8.4 MySql.Data.MySqlClient.Interceptors Namespace...............................................................161

8.5 MySql.Data.MySqlClient.Replication Namespace................................................................161

8.6 MySql.Data.Types Namespace..........................................................................................161

8.7 MySql.Data.EntityFramework Namespace..........................................................................161

8.8 Microsoft.EntityFrameworkCore Namespace.......................................................................163

8.9 MySql.EntityFrameworkCore Namespace...........................................................................163

8.10 MySql.Web Namespace..................................................................................................165

9 Connector/NET Support...............................................................................................................169

9.1 Connector/NET Community Support..................................................................................169

9.2 How to Report Connector/NET Problems or Bugs..............................................................169

10 Connector/NET FAQ..................................................................................................................171

iv

Preface and Legal Notices

This is the developer guide for MySQL Connector/NET. Licensing information. This product may include third-party software, used under license. MySQL Connector/NET Community License Information User Manual has information about licenses relating to Connector/NET community releases up to and including version 7.0. MySQL Connector/NET Commercial License Information User Manual has information about licenses relating to Connector/NET commercial releases up to and including version 7.0. MySQL Connector/NET 8.0 Community License Information User

Manual has information about licenses relating to Connector/NET community releases in the 8.0 release

series. MySQL Connector/NET 8.0 Commercial License Information User Manual has information about licenses relating to Connector/NET commercial releases in the 8.0 release series.

Legal Notices

Copyright © 2004, 2023, Oracle and/or its affiliates.

This software and related documentation are provided under a license agreement containing restrictions

on use and disclosure and are protected by intellectual property laws. Except as expressly permitted 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 any form, or by any

means. Reverse engineering, disassembly, or decompilation of this software, unless required 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 is software or related documentation that is delivered to the U.S. Government or anyone licensing it

on behalf of the U.S. Government, then the following notice is applicable: U.S. GOVERNMENT END USERS: Oracle programs (including any operating system, integrated software, any programs embedded, installed or activated on delivered hardware, and modifications of such programs) and Oracle computer documentation or other Oracle data delivered to or accessed by U.S. Government end users are "commercial computer software" or "commercial computer software documentation" pursuant to the applicable Federal Acquisition Regulation and agency-specific supplemental regulations. As such, the use, reproduction, duplication, release, display, disclosure,

modification, preparation of derivative works, and/or adaptation of i) Oracle programs (including any

operating system, integrated software, any programs embedded, installed or activated on delivered

hardware, and modifications of such programs), ii) Oracle computer documentation and/or iii) other Oracle

data, is subject to the rights and limitations specified in the license contained in the applicable contract.

The terms governing the U.S. Government's use of Oracle cloud services are defined by the applicable contract for such services. No other rights are granted to the U.S. Government. This software or hardware is developed for general use in a variety of information management

applications. It is not developed or intended for use in any inherently dangerous applications, including

applications that may create a risk of personal injury. If you use this software or hardware in dangerous

applications, then you shall be responsible to take all appropriate fail-safe, backup, redundancy, and other

measures to ensure its safe use. Oracle Corporation and its affiliates disclaim any liability for any damages

caused by use of this software or hardware in dangerous applications.

Oracle, Java, and MySQL are registered trademarks of Oracle and/or its affiliates. Other names may be

trademarks of their respective owners.

Intel and Intel Inside are trademarks or registered trademarks of Intel Corporation. All SPARC trademarks

are used under license and are trademarks or registered trademarks of SPARC International, Inc. AMD, v

Documentation AccessibilityEpyc, and the AMD logo are trademarks or registered trademarks of Advanced Micro Devices. UNIX is a

registered trademark of The Open Group. This software or hardware and documentation may provide access to or information about content,

products, and services from third parties. Oracle Corporation and its affiliates are not responsible for and

expressly disclaim all warranties of any kind with respect to third-party content, products, and services

unless otherwise set forth in an applicable agreement between you and Oracle. Oracle Corporation and its

affiliates will not be responsible for any loss, costs, or damages incurred due to your access to or use of

third-party content, products, or services, except as set forth in an applicable agreement between you and

Oracle.

This documentation is NOT distributed under a GPL license. Use of this documentation is subject to the

following terms:

You may create a printed copy of this documentation solely for your own personal use. Conversion to other

formats is allowed as long as the actual content is not altered or edited in any way. You shall not publish

or distribute this documentation in any form or on any media, except if you distribute the documentation in

a manner similar to how Oracle disseminates it (that is, electronically for download on a Web site with the

software) or on a CD-ROM or similar medium, provided however that the documentation is disseminated together with the software on the same medium. Any other use, such as any dissemination of printed

copies or use of this documentation, in whole or in part, in another publication, requires the prior written