Jump to content
  • Advertisement
Sign in to follow this  
toxi

[.net] Connect to MySQL server

This topic is 4094 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, i have a problem again :( I trying to connect to an MySQL server but without success... So far i write this:
string strConn = @"Server='localhost';Database='upoznavanje';Uid='root';Pwd=' ';";

SqlConnection myConn = new SqlConnection(strConn);
myConn.Open();
I have MySQL server on my PC and it's running. When start program, i receive:
Quote:
An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections.
Can someone post here a code that do this correct? [Edited by - toxi on September 25, 2007 12:45:02 PM]

Share this post


Link to post
Share on other sites
Advertisement
No, no i was go to that page alredy, string is OK( i think).
Problem is in something else... :-S

EDIT:

@BASSOFeeSH
Oh no... my mistake in typing, sorry :(

Share this post


Link to post
Share on other sites
Wait, are you trying to connect to SQLServer or MYSQL? And this is c#, right?

The class 'SqlConnection' can ONLY be used for SQLServer, I believe.

Here is the very first google result for "c# mysql"

http://www.csharphelp.com/archives2/archive288.html

Share this post


Link to post
Share on other sites
@Washu
That's it! Now i work just fine.

Thank you all on helping me with this problem. :)

I must ask one more think - i cant connect to MySQL server which is on my web hosting, it does not allow remote connections i suppose. Can i change that or not?

Share this post


Link to post
Share on other sites
You can't change this, but maybe your web hosting service provides some way to access/change data (probably some web interface like Myphpadmin).

Share this post


Link to post
Share on other sites
Quote:
Original post by toxi
@Washu
That's it! Now i work just fine.

Thank you all on helping me with this problem. :)

I must ask one more think - i cant connect to MySQL server which is on my web hosting, it does not allow remote connections i suppose. Can i change that or not?


What you can also do is have your program issue HTTP requests to a script (php, asp, asp.net, ...) on your site which does the actual querying. You may want to restrict access to said script to specific IP addresses or user agents. This can be done with a .htaccess file.

Good luck!

Share this post


Link to post
Share on other sites
@Windryder
This i was using for sometime, but then i start finding a way to do this directly. Then i realize that on most( all?) hostings connection to database could be done only if script/program is on localhost.

But, paid hosting with cPanel offer a way to allow connect to database and from other computers( IP address). To do this, i was go to "mySql" from cPanel and there is "Access Hosts". Only one was be "localhost" but i add "%" and that solve the problem.

BUT! I looking for free hosting with this option. I tray around six different hostings this far and no one of them does not have this "ability".

Know for some hosting that allow this?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!