HaLo2FrEeEk Posted November 13, 2009 Share Posted November 13, 2009 Ok, I have the MySQL Connector installed and referenced in my project. I have "using MySql.Data.MySqlClient;" at the top, I am using this code to connect: private void btnConnect_Click(object sender, EventArgs e) { string strConnection = "Server=[removed];Database=[removed];Uid=[removed];Pwd=[removed];"; MySqlConnection conSQL = new MySqlConnection(strConnection); conSQL.Open(); } (I've removed the values for server, database, user, and password). This should connect to the database when I click the button...well, it doesn't. It returns an error: Access denied for user '[username'@'99-68-44-40.lightspeed.hstntx.sbcglobal.net' (using password: YES) now "'99-68-44-40.lightspeed.hstntx.sbcglobal.net'" is the first hop I get when I run a tracert, so that's my service provider. Why can't I get past my service provider (AT&T) when trying to connect to a MySQL server on the internet through C#? Please help, I can't complete this project (or even go forward) without being able to do this! Quote Link to comment https://forums.phpfreaks.com/topic/181358-solved-connecting-to-mysql-with-c/ Share on other sites More sharing options...
Mchl Posted November 13, 2009 Share Posted November 13, 2009 You have to add access privileges for username'@'99-68-44-40.lightspeed.hstntx.sbcglobal.net user in MySQL http://dev.mysql.com/doc/refman/5.0/en/adding-users.html Be aware, that some hosting companies do not allow remote MySQL access. Quote Link to comment https://forums.phpfreaks.com/topic/181358-solved-connecting-to-mysql-with-c/#findComment-956690 Share on other sites More sharing options...
HaLo2FrEeEk Posted November 14, 2009 Author Share Posted November 14, 2009 Why can I connect to my database via shell if remote access is disabled? I don't understand what exactly I have to do? Adding privelages? This is the command I use to connect to mysql via shell: shell> mysql -h [hostname] -u [username] -p[password] database Should be the same concept right? I'm remotely connecting to the database, is it different because I'm connecting through shell? What privelages would I have to add to be able to access the database from my computer, and would it affect the way I access my database with php on my site? Quote Link to comment https://forums.phpfreaks.com/topic/181358-solved-connecting-to-mysql-with-c/#findComment-957277 Share on other sites More sharing options...
Mchl Posted November 14, 2009 Share Posted November 14, 2009 Are you connecting from you local machine shell, or from remote machine shell? If the latter, you're connecting from 'inside' so to speak. First of all just check what privileges are set already. phpMyAdmin has a nice interface for that. Quote Link to comment https://forums.phpfreaks.com/topic/181358-solved-connecting-to-mysql-with-c/#findComment-957368 Share on other sites More sharing options...
HaLo2FrEeEk Posted November 17, 2009 Author Share Posted November 17, 2009 Ah, I figured it out. I control most of the properties of my databases and accessing user accounts through the control panel at my webhost, I just had to set my username as able to access any database from % hosts (so any host, instead of just %.dreamhost.com, which is the webhost). That made it work. Now I just have to figure out how to reuse query veriables so I can do multiple queries over and over. Right now I have a textarea, a textbox, and a button. You click the menu bar and click connect then you can type a query in the textbox and click the execute button and it'll show the result in the textarea, but when you try to type in a new query and click the Execute button again it throws an error, know any way around that? Quote Link to comment https://forums.phpfreaks.com/topic/181358-solved-connecting-to-mysql-with-c/#findComment-959425 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.