【问题标题】:Unable to connect hosting provider MYSQL database in asp.net无法在 asp.net 中连接托管服务提供商 MYSQL 数据库
【发布时间】:2014-02-09 15:56:43
【问题描述】:

我有来自托管服务提供商 net4.in 的 MYSQL 数据库,但我无法访问数据库。

我的代码如下:

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.Odbc;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class dummy : System.Web.UI.Page
{
 OdbcConnection conn;

    string Address = "Driver={MySql ODBC 5.1 Driver};Server=phpmyadmin7.net4india.com;Option=3;Port=3306;Stmt=;" +
              "DataBase=test;Uid=demo;Pwd=demo123;";
    protected void Page_Load(object sender, EventArgs e)
    {
        string sql = "Select * from test.testing limit 5";
        DataSet rsDSet = new DataSet();
        try
        {
            if (sql == "") throw new Exception("SQL input required");
            conn = new OdbcConnection(Address);
            if (conn.State == ConnectionState.Closed) conn.Open();
            OdbcDataAdapter adp = new OdbcDataAdapter(sql, conn);
            adp.Fill(rsDSet);

        }
        catch (Exception ee)
        {
            Response.Write(ee.ToString());
        }
        GridView1.DataSource = rsDSet;
        GridView1.DataBind();
    }
}

请告诉我如何连接 MYSQL DB。 提前谢谢你

【问题讨论】:

  • 怎么了?有错误吗?超时?段错误?

标签: c# mysql asp.net linq asp.net-4.0


【解决方案1】:

您确定您的 MySQL 实例托管在名为 phpmyadmin7 的机器上吗?似乎不太可能。我相信您知道,Phpmyadmin 是一大块客户端软件的名称。

您确定您的托管服务提供商允许从其数据中心外部访问 MySQL 服务器实例吗? (假设您正在运行您从自己的机器上提供的示例代码,情况可能并非如此。)大多数托管服务提供商会保护他们的 MySQL 实例免受互联网范围的访问,因为否则很容易对它们进行 DDOS 攻击。

在某些托管服务提供商环境中,MySQL 身份验证方案仅允许从运行您的 Web 应用程序的特定机器访问您的 MySQL 实例。

在任何情况下,您都需要与您的支持人员讨论如何执行此操作。

【讨论】:

    猜你喜欢
    • 2013-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-14
    • 1970-01-01
    • 1970-01-01
    • 2020-07-08
    • 1970-01-01
    相关资源
    最近更新 更多