Search code examples
mysqlasp.netasp.net-mvcvb.netmysql-error-1064

MySQL database and ASP.NET global connection


I have developed a website in which I have used ASP.NET with VB.NET as the backend programming language and a MySQL database. I have used ASP.NET and the MySQL database connector to run the website on my local computer, and it is working fine. The code of web.config file is given below:

<?xml version="1.0"?>
<!--
    For more information on how to configure your ASP.NET application, please
    visit
    http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
    <system.web>
        <trust level="Medium"/>
        <customErrors mode="Off" defaultRedirect="Home.aspx"/>
        <compilation debug="true" strict="false" explicit="true"
                     targetFramework="4.0">
            <assemblies>
                <add assembly="MySql.Data, Version=6.9.9.0, Culture=neutral,
                     PublicKeyToken=C5687FC88969C44D"/>
            </assemblies>
        </compilation>
    </system.web>
</configuration>

But now I have uploaded this website and database on the global server and have put the global database connection in my code. now the code of web.config file is

<?xml version="1.0"?>
<!--
    For more information on how to configure your ASP.NET application, please
    visit
    http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
    <connectionStrings>
        <add name="myConnectionString" connectionString= "Server=globalservername;
             Database=databasename; Uid=userid; Pwd=passwd;"
             providerName="MySql.Data.MySqlClient" />
    </connectionStrings>
    <system.web>
        <trust level="Medium"/>
        <customErrors mode="Off" defaultRedirect="Home.aspx"/>
        <compilation debug="true" strict="false" explicit="true"
                     targetFramework="4.0">
        </compilation>
    </system.web>
</configuration>

And when I open any page then it is showing the following error

Compiler Error Message: BC30002: Type 'MySqlConnection' is not defined.

in this line which is in every Visual Basic file of my project (connection string):

Dim SQLConnection As New MySqlConnection("Server=globalservername;
Database=databasename; Uid=userid; Pwd=passwd;")

What should I add or remove in the web.config file to remove this error?


Solution

  • You might be missing the required DLL file, MySQL.Data in a production environment. You can use the NuGet package* MySQL.Data* then build and deploy.

    Alternatively, you can place the MySQL.Data DLL file in your bin folder and deploy.