MySql Database Connection String with C# code snippets

In this article, find out list of MySql database connection string with C# code snippets. In this article you can see how to create connector.NET connection string for MySql database. You can find the MySql database connection string template with all the configuration parameters.


MySql Database Connection String in C#:

Connection String provide the required information to the driver that tells where to find the default connection information. Optionally, you are allowed to specify attribute=value pairs in the connection string to override the default values stored in the data source.

1. Standard or basic MySql connection string:

Server: Specify the server name where the MySQL database is located. You can enter the IP address as the server name.
Database: Specify the name of the MySql database.
Uid: Specify the username.
Pwd: Specify the password

For instance, if your MySql database is located in your local computer then you can write the connection string like this below.

2. Standard or basic MySql connection string with multiple servers:

Use the following connection string template when you have MySql databse is located in different servers.

3. Standard or basic MySql connection string with TCP port:

Port: Specify the port name. The default port number is set to 3306 if the Port property is not included in the connection string. Also, note that Port value is ignored if you have used Unix socket.

4. Standard or basic MySql connection string with SSL Encryption

The server must have installed a certificate in order to use SSL encrypted data to be set send across client and server.

Encrypt: The Encrypt property enable SSL encryption data transfer between client and server. This configuration property is available from .NET version 5.0.3 to 6.2.1.



SslMode: The Encrypt configuration property is replaced with SslMode from .NET version 6.2.1 version onwards.
SslMode=Preferred: Preferred encryption.
SslMode=Required: Forced encryption.


You can also have MySql connection string with SSL specific personal store based certificate. Here is the connection string template.

Certificate Store Location: The certificate store location name. This configuration is available from .NET version 6.2.1


You can also have MySql connection string with SSL thumbprint specific personal store based certificate. Here is the connection string template.

Certificate Thumbprint: The certificate thumbprint text. This configuration is available from .NET version 6.2.1


You can also have MySql connection string with SSL file based certificate. Here is the connection string template.

CertificateFile: The absolute path of certificate file location.
CertificatePassword: The certificate password.
This configuration is available from .NET version 6.2.1 onwards.


5. MySql connection string with Disallow batch:

6. MySql connection string with Allow User Variables:

1. ODBC DSN

2. ODBC – MyODBC Driver (local database)

3. ODBC – MyODBC Driver (remote database)

4. ODBC – MySQL ODBC 3.51 Driver

5. OleDb

6. .NET DataProvider from CoreLab



– Article ends here –

Recommended:   Simulating Blue Screen Of Death - BOSD error in C#
Share this:

Kiran is a Software engineer by profession and Enthusiastic blogger, love to write articles on computer technology and programming. Reach him at kiran.troubleshootyourself@gmail.com.

We will be happy to hear your thoughts

Leave a reply

Troubleshootyourself
Logo