Visual Studio 2017和2019 SqlDataSource“无法连接 - 对象引用未设置为对象的实例”

问题描述 投票:-1回答:1

我正在为我的研究生课程开发一个项目,需要使用gridview从mysql填充数据,然后填充链接以编辑和删除所述数据。我似乎无法在网上找到这个问题的答案。通过向导测试连接字符串,连接成功。

我试过降级版本,正如其他帖子所建议的那样。我已经安装了2017年的视觉工作室,因为我认为2019年可能不受支持。但是,无论我做什么,我都会遇到同样的错误,通过我的c#和html网站的sqldatasoure向导“无法连接 - 对象引用未设置为对象的实例”。

我认为它可能只是我的项目经过几个小时的调试,然而,当我创建一个带有单个网页的空项目时,我得到了同样的错误。

这与null异常不同,因为我认为它与具有net连接器的mysql和visual studio本身相关,而不是null对象。我认为mysql插件扩展有问题。

网页:

<%@ 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>

网页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>

c# html mysql gridview sqldatasource
1个回答
0
投票

为visual studio卸载mySQL并仅使用连接字符串解决了这个问题。 MySQL中用于可视工作室的连接器导致了连接问题。

© www.soinside.com 2019 - 2024. All rights reserved.