0

So I'm building this asp website for my school project. I'm using Visual Studio 2010-C# for the development and MySql for Database. I attached SqlDataSource from Tools and it gave me a connectionString in Web.config and it like goes like this:

<connectionStrings>
<add name="webServerConnectionString" connectionString="user id=root;password=root;persistsecurityinfo=True;server=127.0.0.1;database=webServer" providerName="MySql.Data.MySqlClient"/>
</connectionStrings>

Now, I'm having trouble to what I should write inside the Register.aspx if I want to use that connection and input data to database. This is what I formulated at the moment. I think its incomplete, I just don't know what to add. I already added MySql.data in References.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MySql.Data.MySqlClient;
using System.Data.SqlClient;
using System.Configuration;

namespace hproj
{

public partial class Register1 : System.Web.UI.Page
{

    MySql.Data.MySqlClient.MySqlConnection con = new MySql.Data.MySqlClient.MySqlConnection();

    protected void Page_Load(object sender, EventArgs e)
    {
        con.Open();
    }

    protected void regcreate_Click(object sender, EventArgs e)
    {
        MySqlCommand cmd = new MySqlCommand("INSERT INTO login(userid, user_pass, email) VALUES ('"+reguname+"','"+regpword+"','"+regemail+"')", con);
        cmd.ExecuteNonQuery();
        con.Close();
        reglabel.Visible = true;
        reglabel.Text = "Account Creation Successful";
        reguname.Text = "";
        regpword.Text = "";
        regconfirmpword.Text = "";
        regemail.Text = "";
    }
}

This string gives me the error even though I have full permission and authority in MySql Workbench:

Host 'Han-PC' is not allowed to connect to this MySQL server
Han
  • 1
  • 2
  • You get any exception or error message in your code? And use parameterized queries. This kind of string concatenations are open for SQL Injection attacks. – Soner Gönül Feb 21 '15 at 14:06
  • MySql doesn't allow me to connect to the database.. It is implying that I'm not allowed to Connect to that server even though I have all permissions.. Can you give me an example of a good connectionString and query? – Han Feb 21 '15 at 15:36
  • Possible duplicate of [Why am I getting "Host '192.168.1.220' is not allowed to connect to this MySQL server"?](http://stackoverflow.com/questions/18158770/why-am-i-getting-host-192-168-1-220-is-not-allowed-to-connect-to-this-mysql-s) – Vahid Farahmandian Oct 28 '16 at 17:07
  • The question seems to be a duplicate question, however you can check this answer: http://stackoverflow.com/a/19101356/1666800 – Vahid Farahmandian Oct 28 '16 at 17:08

0 Answers0