I have scoured Google trying to discover how to do this, but essentially I want to connect to a colleague's MySQL database for working together on a Wordpress installation.
I am having no luck and keep getting an error about the connection not being possible:
Unable to connect to any of the specified MySQL hosts.
MySql.Data.MySqlClient.MySqlException (0x80004005): Unable to connect to any of the specified MySQL hosts.
at MySql.Data.MySqlClient.NativeDriver.Open()
at MySql.Data.MySqlClient.Driver.Open()
at MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings)
at MySql.Data.MySqlClient.MySqlPool.GetPooledConnection()
at MySql.Data.MySqlClient.MySqlPool.TryToGetDriver()
at MySql.Data.MySqlClient.MySqlPool.GetConnection()
at MySql.Data.MySqlClient.MySqlConnection.Open()
at Microsoft.WebMatrix.DatabaseManager.MySqlDatabase.MySqlDatabaseProvider.TestConnection(String connectionString)
at Microsoft.WebMatrix.DatabaseManager.IisDbManagerModuleService.TestConnection(DatabaseConnection databaseConnection, String configPathState)
at Microsoft.WebMatrix.DatabaseManager.Client.ClientConnection.Test(ManagementConfigurationPath configPath)
at Microsoft.WebMatrix.DatabaseManager.Client.DatabaseHierarchyInfo.EnsureLoaded()
The connection details are copied from my colleague's connection string, with the exception of the server being modified to match the IP address of his machine.
I'm not sure if there is a firewall port I have to open or a configuration file I have to modify, but I'm not having much luck so far.
(There is a strong chance that, by default, web matrix / iis express doesn't set the mysql database it creates to accept remote connections. If anyone knows how to change this, that would be grand!)
Anyone have any ideas?
EDIT : Port Opened
I opened the port 3306 on Windows Firewall on my colleague's machine.
Now I have the following error:
Host 'DESKTOP019-PC' is not allowed to connect to this MySQL server
MySql.Data.MySqlClient.MySqlException (0x80004005): Host 'DESKTOP019-PC' is not allowed to connect to this MySQL server
at MySql.Data.MySqlClient.MySqlStream.ReadPacket()
at MySql.Data.MySqlClient.NativeDriver.Open()
at MySql.Data.MySqlClient.Driver.Open()
at MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings)
at MySql.Data.MySqlClient.MySqlPool.GetPooledConnection()
at MySql.Data.MySqlClient.MySqlPool.TryToGetDriver()
at MySql.Data.MySqlClient.MySqlPool.GetConnection()
at MySql.Data.MySqlClient.MySqlConnection.Open()
at Microsoft.WebMatrix.DatabaseManager.MySqlDatabase.MySqlDatabaseProvider.TestConnection(String connectionString)
at Microsoft.WebMatrix.DatabaseManager.IisDbManagerModuleService.TestConnection(DatabaseConnection databaseConnection, String configPathState)
at Microsoft.WebMatrix.DatabaseManager.Client.ClientConnection.Test(ManagementConfigurationPath configPath)
at Microsoft.WebMatrix.DatabaseManager.Client.DatabaseHierarchyInfo.EnsureLoaded()
I think I need to grant my hostname permissions for this user, but given that I don't know where the database is or how to access it via command line (there's no proper MySQL folder in program files), it's going to prove difficult.
EDIT : Found MySQL Client
Located in
Start > All Programs > MySQL > MySQL Server %version% > MySQL Command Line Client
http://forums.iis.net/t/1173668.aspx
EDIT : Grant User Priveleges
After finding the sql client, fixing the connection was done by entering the following command:
GRANT ALL PRIVILEGES ON databasename.* to ‘databaseuser’@'hostname' IDENTIFIED BY 'databasepassword';
http://31bit.com/technology/86-mysql-database/302-how-to-grant-remote-access-to-a-mysql-database
Thanks to DKNUCKLES for the port push. I was going crazy looking for config files and things for IIS express, but a port opening and granting user permissions was all it took!
EDIT: Access Denied in Wordpress install.
Now I have connected, I get access denied via wordpress. I was getting "Error establishing database connection" which was a pretty vague error.
I did a search and found a page which can test the connection:
testconnection.php
<?php
$link = mysql_connect('databaseip_or_localhost', 'databaseuser', 'databasepassword');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>
I put in the correct credentials, added the page to my wordpress installation and visited it.
I got the message:
Could not connect: Access denied for user 'wordpressuser457'@'DESKTOP019-PC' (using password: YES)
It turned out that I had written the username wrong also (I was having a really long day) - it should have been wordpress457user
NOT wordpressuser457
.
Hate it when a dumb thing takes you ages to find.
Hope this helps anyone else looking to do the same in future.