[.net] Connect to MySQL server

Started by
8 comments, last by toxi 16 years, 6 months ago
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]
Advertisement
You probably don't have the right connection string. For MySql go here:

http://www.connectionstrings.com/?carrier=mysql
Looks like you're missing a single quote after PWD.
-- What would Sweetness do?
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 :(
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
-- What would Sweetness do?
There is also a MySQL connector out. I believe you can obtain it from the MySQL web site.

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.

@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?
You can't change this, but maybe your web hosting service provides some way to access/change data (probably some web interface like Myphpadmin).
<br/>GDNet journal: Endeavours On Managed Code Land
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!
@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?

This topic is closed to new replies.

Advertisement