Forum Moderators: open

Message Too Old, No Replies

how to connect to mysql from local host

         

sixeleven

4:40 pm on Aug 1, 2008 (gmt 0)

10+ Year Member



hi
i have written a program with c# .net ,and i want to connect remotely from my pc to my website's mysql database.

this programm ,work perfectly in my localhost and i can connect to mysql on my pc .
but i can not connect to mysql on my website,and it says ,that can not connect to it and show me this exception

System.Data.Odbc.OdbcException: ERROR [HYT00] [MySQL][ODBC 3.51 Driver]Can't connect to MySQL server on 'mysitename.com' (10051)
at System.Data.Odbc.OdbcConnection.HandleError(OdbcHandle hrHandle, RetCode retcode)
at System.Data.Odbc.OdbcConnectionHandle..ctor(OdbcConnection connection, OdbcConnectionString constr, OdbcEnvironmentHandle environmentHandle)
at System.Data.Odbc.OdbcConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup)
at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
at System.Data.Odbc.OdbcConnection.Open()
at Reflex.Connect.btn_connect_Click(Object sender, EventArgs e) in F:\myprogram\Reflex\connect.cs:line 37

what should i do ?

rocknbil

11:17 pm on Aug 1, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



First, determine where the problem is.

Does the web server's database work when you run your scripts from it? To test, upload your script to your server, see if it will connect there. If the mySQL server is on the same server as your domain, it may connect correctly via localhost when uploaded.

Next, does your mySQL configuration allow connections remotely? mySQL is designed to remotely connect, but configurations or firewalls may disallow any remote connections. Check with the host company to verify, and also verify the correct URL/domain/IP of the mySQL server.

If both of the above work out, it's possible you're using the wrong URL to reference the mySQL database. Verify that, or, connect via the IP address of the mySQL server.

sixeleven

6:50 pm on Aug 2, 2008 (gmt 0)

10+ Year Member



tanx,i think i should email to host company.
but it is not dangerous for my website ,to allowed remote access from localhost?

rocknbil

7:22 pm on Aug 2, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



"allowed remote access from localhost"

This is a bit confusing, let me clarify.

"localhost" means anything local to the current location.

When you are on YOUR PC, testing a script also on your PC, and you have mysql installed on your pc, it connects via localhost. No mysql host specification is required, or you specify "localhost".

When you are on YOUR SERVER, and mysql is installed on the same server, you also connect via localhost; if you don't specify a mysql server, it will also attempt to connect via localhost.

However, let's say you have the mysql host on a different server:

mydomain.com (your web site)
your-web-host.mysqlservers.com (a physically different machine than your web site.)

The only option here is to connect remotely. This is how mysql is designed. It doesn't matter if the mysql server is on the same internal network or halfway around the world, you have to specify the host and connect remotely.

A firewall or some other configuration can *possibly* block any connections from outside the internal network, but otherwise you should be able to connect to your web site's database from your PC unless such configurations are in place.

The mySQL user and password will be supplied in making the connection. This is what logs your program in to your database. It shouldn't be dangerous unless your machine is compromised.

sixeleven

12:17 pm on Aug 3, 2008 (gmt 0)

10+ Year Member



tanx :)