VS2017 MYSQL SQLDataSource - Object reference not set to an instance of an object

大城市里の小女人 提交于 2019-12-11 07:10:40

问题


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.



来源:https://stackoverflow.com/questions/48099305/vs2017-mysql-sqldatasource-object-reference-not-set-to-an-instance-of-an-objec

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!