求解!!“System.Data.SqlClient.SqlException”类型的异常

使用vs调试网站时候出现一下问题。

“System.Data.SqlClient.SqlException”类型的异常在 System.Data.dll 中发生,但未在用户代码中进行处理

其他信息: 在与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误。未找到或无法访问服务器。请验证实例名称是否正确并且 SQL Server 已配置为允许远程连接。 (provider: SQL Network Interfaces, error: 26 - 定位指定的服务器/实例时出错)

代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class UserController_top : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
Bind();
}
}

/// <summary>
/// 按照影片的点击排行,
/// </summary>
public void Bind()
{
    string str = "select top 10 * from Movies order by MovieHit desc";
    SqlConnection con = DB.getConnection();
    DataSet ds = new DataSet(); //多行数据填充到数据集中
    SqlDataAdapter sda = new SqlDataAdapter(str, con);
    sda.Fill(ds, "Movie");
    this.DataList1.DataSource = ds.Tables["Movie"].DefaultView;
    DataList1.DataBind();
}
protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
    if (e.CommandName == "Play"){
    string hit = (e.Item.FindControl("Label8") as Label).Text;

    string str = (e.Item.FindControl("Lable20") as Label).Text;

    int id = Convert.ToInt32(str); //影片的ID号
    int num = Convert.ToInt32(hit) + 1; //以前的播放次数加上1就为当前的播放次数

    SqlConnection con = DB.getConnection();
    con.Open();
    SqlCommand cmd = new SqlCommand("update Movies set MovieHit=" + num + " where MovieID=" + id + "", con);
    cmd.ExecuteNonQuery();
    con.Close();
    Response.Redirect("Play.aspx?ID=" + id);

    }
}

}

问题代码:
sda.Fill(ds, "Movie");

软件版本:visualstudio2013+mysql5.6

你检查一下变量 con ,可能是数据库没有正确的连接!

删除数据库后重新连接还是不行。

主要问题可能出现在你的DB.getConnection();方法里,最好到里面找找看,是不是ConnectionString有问题,还是服务器有问题