简体   繁体   English

无法在asp.net中连接托管服务提供商MYSQL数据库

[英]Unable to connect hosting provider MYSQL database in asp.net

I have MYSQL database from Hosting provider net4.in and i am unable to access database. 我有Hosting provider net4.in的MYSQL数据库,但无法访问数据库。

My code is as below : 我的代码如下:

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();
    }
}

Pl let me know how can i connect MYSQL DB. 请让我知道如何连接MYSQL DB。 Thank you in advance 先感谢您

Are you sure your MySQL instance is hosted on a machine named phpmyadmin7? 您确定您的MySQL实例托管在名为phpmyadmin7的计算机上吗? It seems unlikely. 似乎不太可能。 Phpmyadmin is the name of a chunk of client software, as I am sure you know. 如我所知,Phpmyadmin是很多客户端软件的名称。

Are you sure your hosting provider allows access from outside their data center to MySQL server instances? 您确定托管服务提供商允许从其数据中心外部访问MySQL服务器实例吗? (Presuming you are running the sample code you provided from your own machine, which might not be the case.) Most hosting providers protect their MySQL instances from internet-wide access because it is easy to mount DDOS attacks against them otherwise. (假定您正在运行从您自己的计算机提供的示例代码,情况可能并非如此。)大多数托管服务提供商会保护他们的MySQL实例免受Internet范围的访问,因为否则很容易对它们进行DDOS攻击。

In some hosting provider environments the MySQL authentication scheme only allows access to your MySQL instance from the particular machine upon which your web apps run. 在某些托管提供程序环境中,MySQL身份验证方案仅允许从运行Web应用程序的特定计算机上访问MySQL实例。

In any case you need to have a conversation with your support crew about how to do this. 无论如何,您都需要与支持人员进行有关如何进行此操作的对话。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM