-1

I am working on a project for my graduate classes and need to use gridview to populate data from mysql and then populate links to edit and delete said data. I cannot seem to find the answer anywhere online to this problem. The connection string was tested through a wizard and the connection succeeded.

I have tried downgrading versions as other post suggested. I have installed visual studio 2017 as I thought maybe 2019 wasn't supported. However, no matter what I do I run into the same error going through the sqldatasoure wizard for my c# and html website "Cannot connect - Object Reference not set to an instance of an object".

I thought it may have just been my project after hours of debugging, however, when I created an empty project with a single webpage I got the same error.

This is different than a null exception because I think it is relative to the mysql and visual studio itself with the net connector, not a null object. I think there is an issue with the mysql addon extension or something.

Web page:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
        </div>

<asp:gridview runat="server"></asp:gridview>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:starssparksConnectionString %>" ProviderName="<%$ ConnectionStrings:starssparksConnectionString.ProviderName %>" SelectCommand="SELECT * FROM [cart]"></asp:SqlDataSource>
    </form>
</body>
</html>

Web page aspx:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
}

Web.config:

<?xml version="1.0"?>

<!--
  For more information on how to configure your ASP.NET application, please visit
  https://go.microsoft.com/fwlink/?LinkId=169433
  -->

<configuration>

    <connectionStrings>
        <add name="starssparksConnectionString" connectionString="server=localhost;user id=root;password=PASSWORD;persistsecurityinfo=True;database=starssparks"
            providerName="MySql.Data.MySqlClient" />
    </connectionStrings>
    <system.web>
      <compilation debug="true" targetFramework="4.6.1"/>
      <httpRuntime targetFramework="4.6.1"/>
    </system.web>
    <system.codedom>
        <compilers>
            <compiler language="c#;cs;csharp" extension=".cs"
                type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701"/>
            <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb"
                type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+"/>
        </compilers>
    </system.codedom>

</configuration>

Brooke
  • 109
  • 1
  • 2
  • 12
  • 1
    Possible duplicate of [What is a NullReferenceException, and how do I fix it?](https://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – Frontear Apr 25 '19 at 02:32

1 Answers1

0

Uninstalling mySQL for visual studios and using only a connection string resolved this problem. The connector in the mySQL for visual studios was causing a connection issue.

Brooke
  • 109
  • 1
  • 2
  • 12