VS2017 MYSQL SQLDataSource - Object reference not

2019-07-25 11:44发布

问题:

So, I am trying to run a query using SQLDataSource on VS with MYSQL, and whatever the query is, I get the same error which is Object reference not set to an instance of an object.
The SQLDataSource is already connected to the database, so there is nothing wrong with my connection string.


Web.config

<?xml version="1.0"?>
<configuration>
  <connectionStrings>
    <add name="helbotelConnectionString" connectionString="Data Source=localhost;port=3306;Initial Catalog=helbotel;User Id=root;password=MYPASSWORD"
      providerName="MySql.Data.MySqlClient" />
  </connectionStrings>
  <system.web>
    <compilation debug="false" targetFramework="4.0">
      <assemblies>
        <add assembly="MySql.Data, Version=6.10.5.0, Culture=neutral, PublicKeyToken=C5687FC88969C44D"/>
      </assemblies>
    </compilation>
  </system.web>
</configuration>


SQLDataSource

<asp:SqlDataSource ID="sqlNews" runat="server" ConnectionString="<%$ ConnectionStrings:helbotelConnectionString %>" ProviderName="<%$ ConnectionStrings:helbotelConnectionString.ProviderName %>" SelectCommand="SELECT * from users"></asp:SqlDataSource>


Error Page Error page screenshot

P.S: I already use mysql connections from backcode and they work perfectly but this problem only occurs with SQLDataSource (I need it for GridView)

回答1:

Issue with MySQL for Visual Studio / Visual Studio 2017 Datasource Wizard. Object reference not set to an instance of an object

I had the same issue, the following resolved it:

  • Uninstalled MySQL for Visual Studio
  • Uninstalled MySQL Connector/Net
  • Re-Installed Latest Version for MySQL for Visual Studio
  • Installed Previous Version for MySQL Connector/Net (6.9.11)
  • Downgraded MySQL.Data to 6.9.11
  • Downgraded MySQL.Web to 6.9.11

There appears to be an issue with the latest version of Connector/NET.

I have posted this as a MySQL Connector/NET Bug.