Protected by Sectigo SSL

How can I connect to a MySQL database through .NET?

MySQL Connection Strings on a Windows hosted site
All Windows shared servers have the Connector/Net 6.0 connector, MySQL's fully managed ADO.Net provider, installed. The current version we use is 6.0.4.

Documentation on this connector is available from , however for convenience, here are a few common examples of connection strings you can use:

Standard
Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;

Specifying TCP port
Server=myServerAddress;Port=1234;Database=myDataBase;Uid=myUsername; Pwd=myPassword;
The port 3306 is the default MySql port.

The value is ignored if Unix socket is used.

Multiple servers
Use this to connect to a server in a replicated server configuration without concern on which server to use. Server=serverAddress1, serverAddress2, serverAddress3;Database=myDataBase; Uid=myUsername;Pwd=myPassword;

Using encryption
This one activates SSL encryption for all data sent between the client and server. The server must have a certificate installed. Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword; Encrypt=true;

Disallow batches
Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword; AllowBatch=False;

Allow User Variables
Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword; AllowUserVariables=True;

Allow Invalid Date/Time 1
Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword; AllowZeroDateTime=True;
Returns a MySqlDateTime object for invalid values and a System.DateTime object for valid values.

Allow Invalid Date/Time Alternative
Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword; ConvertZeroDateTime=True;
Returns System.DateTime.MinValue valued System.DateTime object for invalid values and a System.DateTime object for valid values.

Disable transaction participation
The use of auto enlist transactionscope (default behaviour) could cause trouble in medium trust environments. Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword; AutoEnlist=False;

Skip parameter checks for stored routines
Default behaviour is that parameters for stored routines (stored procedures) are checked against the server Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword; CheckParameters=False;

Some permissions and value casting related errors reported fixed when using this connection option.
Skip parameter type and order matching for stored procedures Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword; UseProcedureBodies=False;

The default behaviour is to read tables mysql.proc/INFORMATION_SCHEMA.ROUTINES and try to map provided command parameter values to the called procedures parameters and type cast values accordingly.

This can be an issue if permissions to the earlier mentioned sproc info tables are not sufficient.

The driver will not automatically map the parameters so you must manually set parameter types and you must also make sure to add the parameters to the command object in the exact order as appeared in the procedure definition.

Count changed rows rather than found rows
Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword; UseAffectedRows=True;

Compress network communication between client and server
Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword; UseCompression=True;

Log inefficient database operations
Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword; UseUsageAdvisor=True;

Enable performance counters
Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword; UsePerformanceMonitor=True;

  • Email, SSL
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

Can I use Microsoft SQL Server Management Studio to manage my MSSQL database?

We run Microsoft SQL Server 2008 on our servers, only Microsoft SQL Server Management Studio 2008...

Can I connect to a MSSQL database from my linux shared hosting account?

Yes, you can connect to MSSQL databases through PHP5 via the ms_sql extension and the ms_sqli...

How do I connect to MySQL with ASP?

This applies to Windows Hosting accounts only. You will need to use a DSNless connection which...

I'm getting SQL errors on MySQL 5 saying it can't find a column - but it's there!

1054 - Unknown column 'a.c' in 'on clause'This can happen if you're doing something like:SELECT *...

How can I connect remotely to my MySQL database?

Once logged into your hosting control panel go to Web Tools > Remote MySQL and this will take...