【问题标题】:I'm Getting an Exception about Connecting My SQL Server我在连接我的 SQL Server 时遇到异常
【发布时间】:2018-08-04 09:58:33
【问题描述】:
    private void frmResibo_Load(object sender, EventArgs e)
    {

        market m = new market();
        string cs = @"Data Source =.localhost; Initial Catalog = thesisdb; User ID=root; Integrated Security = true";
        SqlConnection cn = new SqlConnection(cs);
        SqlDataAdapter da = new SqlDataAdapter("select * from tbl_itemlist", cn);
        da.Fill(m, m.Tables[0].TableName);



         ReportDataSource rds = new ReportDataSource("tbl_itemlist", m.Tables[0]);
         this.reportViewer1.LocalReport.DataSources.Clear();
         this.reportViewer1.LocalReport.DataSources.Add(rds);
         this.reportViewer1.LocalReport.Refresh();

         this.reportViewer1.RefreshReport();

    }

我在"da.Fill--- 行中遇到这样的错误

System.Data.SqlClient.SqlException: '建立与 SQL Server 的连接时发生与网络相关或特定于实例的错误。服务器未找到或无法访问。验证实例名称是否正确以及 SQL Server 是否配置为允许远程连接。 (提供者:命名管道提供者,错误:40 - 无法打开与 SQL Server 的连接)'

【问题讨论】:

  • 您正在使用 C# SQL-server 客户端连接到 MySQL 服务器。 google.nl/search?q=C%23+mysql
  • 你需要安装mysql连接器并且需要使用它的dll。连接类将是 MySQLConnection
  • 你也缺少 con.open()
  • 我尝试放置 con.Open() 但仍然出现错误,也尝试使用 MySQLConnecting 并且仍然相同。请帮忙
  • Data Source =.localhost 我想你只是想要localhostMy SQL Server 非常模糊...... System.Data.SqlClient 是为 Microsoft SQL Server 的。

标签: c# mysql


【解决方案1】:

连接字符串指定“Data Source =.localhost”;通常您会输入“Data Source = .”或“数据源 = localhost”(两者的含义相同:运行它的计算机)。但是在 localhost 前面有那个点,它可能会尝试寻找名为“.localhost”的机器,这可以解释为什么它无法连接到那个 SQL 服务器。

另请注意,您的 SQL 连接和数据适配器是一次性的,因此应该在“使用”块中。

【讨论】:

    猜你喜欢
    • 2016-04-07
    • 2012-04-19
    • 2011-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多