Technology and More

MySQL Connection String for ASP.NET

Posted by: David Hill on

Here is an example MySQL connection string for ASP.NET:

<add name="data" connectionString="Server=localhost; Database=world;Uid=myUserId;Pwd='PaSsWoRd'" providerName="MySql.Data.MySqlClient" />

To use the connection string properly, a reference must be added to the project for the MySQL Data connector assembly. A search for "MySql.Data.dll" in the \Windows folder turned up several locations:

C:\Windows\Microsoft.NET\assembly\GACMSIL\MySql.Data\v4.08.0.20.0__c5687fc88969c44d\MySql.Data.dll

C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\PrivateAssemblies\MySql.Data.dll

(note: this dev environment uses Microsoft Visual Studio 2019 Community Edition)

and if MySQL is installed in the development environment, a connector can be found here:

C:\Program Files (x86)\MySQL\Connector NET 8.0\Assemblies\v4.5.2\MySql.Data.dll