mySQL startup

thegriff

New Member
Messages
14
Reaction score
0
Points
0
mySQL startup [Solved]

My bad: I assumed "remote access" was for paid access only.

Changing "localhost" in the connection string to "mysql.x10hosting.com" worked like a charm.
Working connection string:
"server=mysql.x10hosting.com;user id=thegriff_dummy;password=dummy;database=thegriff_testing;"

Please note: "dummy" is no longer a valid user for any database under my control.





I am a complete beginner at this, and have a problem, which has taken me all yesterday to get no-where on.

I have created a mySQL database, called "testing" so accessed via "thegriff_testing" using myphpAdmin, and populated it.
I have given it a user "dummy", with a password "dummy" - these will be removed when I get it working and go to a "proper" database.
I have created a "bin" directory, and uploaded the "mySQL.Data.dll" assembly.
I have duplicated this on my local machine.
I have created some C# code to access the database:
Code:
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]private[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] FillLabel()[/SIZE]
[SIZE=2]{[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]string[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] strFilter = [/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"SELECT LastName, Donation FROM Supporters"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]string[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] strConnect = AddResponse([/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"server="[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] ,tbServer.Text);[/SIZE]
[SIZE=2]strConnect += AddResponse([/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"user id="[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], tbUser.Text);[/SIZE]
[SIZE=2]strConnect += AddResponse([/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"password="[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], tbPassword.Text);[/SIZE]
[SIZE=2]strConnect += AddResponse([/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"database="[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], tbDatabase.Text);[/SIZE]
[SIZE=2]strConnect += AddResponse([/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]""[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] , tbOther.Text);[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] (strConnect.EndsWith([/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]";"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]))[/SIZE]
[SIZE=2]  {[/SIZE]
[SIZE=2]  strConnect = strConnect.Substring(0, strConnect.Length - 1);[/SIZE]
[SIZE=2]  }[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] (![/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]string[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].IsNullOrEmpty(tbMinDonation.Text))[/SIZE]
[SIZE=2]  {[/SIZE]
[SIZE=2]  strFilter += [/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]" WHERE (Donation > "[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] + tbMinDonation.Text + [/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]")"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE]
[SIZE=2]  }[/SIZE]
[SIZE=2]DataOutput.Text = [/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"Supporter's Donations"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] + [/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"<br/>"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE]
[SIZE=2]DataOutput.Text += [/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"---------------------------"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] + [/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"<br/>"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE]
[SIZE=2]DataOutput.Text += strConnect + [/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"<br/>"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]try[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2]  {[/SIZE]
[SIZE=2]  hookUp = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]MySqlConnection[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2](strConnect);[/SIZE]
[SIZE=2]  DataOutput.Text += [/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"Connected<br/>"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE]
[SIZE=2]  sqlCmd = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]MySqlCommand[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2](strFilter, hookUp);[/SIZE]
[SIZE=2]  DataOutput.Text += [/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"Command created<br/>"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE]
[SIZE=2]  hookUp.Open();[/SIZE]
[SIZE=2]  DataOutput.Text += [/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"Opened<br/>"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE]
[SIZE=2]  reader = sqlCmd.ExecuteReader();[/SIZE]
[SIZE=2]  DataOutput.Text += [/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"Executed<br/>"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]while[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] (reader.Read())[/SIZE]
[SIZE=2]     {[/SIZE]
[SIZE=2]     dona = [/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]Convert[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].ToString(reader[[/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"Donation"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]]);[/SIZE]
[SIZE=2]     ln = [/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]Convert[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].ToString(reader[[/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"LastName"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]]);[/SIZE]
[SIZE=2]     DataOutput.Text += ln + [/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]" donated $"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] + dona + [/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"<br/>"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE]
[SIZE=2]     }[/SIZE]
[SIZE=2]  }[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]catch[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] ([/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]Exception[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] ex)[/SIZE]
[SIZE=2]  {[/SIZE]
[SIZE=2]  DataOutput.Text += ex.ToString();[/SIZE]
[SIZE=2]  }[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]finally[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2]  {[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] (reader != [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]null[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2]     {[/SIZE]
[SIZE=2]     reader.Close();[/SIZE]
[SIZE=2]     }[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] (hookUp != [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]null[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2]     {[/SIZE]
[SIZE=2]     hookUp.Close();[/SIZE]
[SIZE=2]     }[/SIZE]
[SIZE=2]  }[/SIZE]
[SIZE=2]}[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]private[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]string[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] AddResponse([/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]string[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] p, [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]string[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] p_2)[/SIZE]
[SIZE=2]{[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] ([/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]string[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].IsNullOrEmpty(p_2))[/SIZE]
[SIZE=2]  {[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]return[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]null[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE]
[SIZE=2]  }[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]return[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] p + p_2 + [/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]";"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE]
[SIZE=2]}[/SIZE]

When I run it locally, it works fine. When I run it on X10hosting, i get:
Code:
Supporter's Donations
---------------------------
server=localhost;user id=thegriff_dummy;password=dummy;database=thegriff_testing;
Connected
Command created
MySql.Data.MySqlClient.MySqlException: Unable to connect to any of the specified MySQL hosts. 
---> System.Net.Sockets.SocketException: 
       Connection refused at System.Net.Sockets.Socket.Connect (System.Net.EndPoint remote_end)[0x00000]
       at System.Net.Sockets.Socket+Worker.Connect () [0x00000] 
--- End of inner exception stack trace --- 
 
at MySql.Data.MySqlClient.NativeDriver.Open ()[0x00000] 
at MySql.Data.MySqlClient.Driver.Create (MySql.Data.MySqlClient.MySqlConnectionStringBuilder settings) [0x00000] 
at MySql.Data.MySqlClient.MySqlPool.CreateNewPooledConnection () [0x00000] 
at MySql.Data.MySqlClient.MySqlPool.GetPooledConnection () [0x00000] 
at MySql.Data.MySqlClient.MySqlPool.TryToGetDriver () [0x00000]
I get the same regardless of "user id": I have tried "thegriff_dummy", "dummy" and completely unrelated ones with no change in message.
Which seems to imply that it is a problem in actually connecting to mySQL.
What have I forgotten to do?
 
Last edited:

xav0989

Community Public Relation
Community Support
Messages
4,467
Reaction score
95
Points
0
Looking over your code, some spaces seem to be missing...

It seems you are missing
Code:
hookUp.Open();
after
Code:
hookUp = newMySqlConnection(strConnect);
 
Last edited:

thegriff

New Member
Messages
14
Reaction score
0
Points
0
Thanks for the sugestion, but it was already there, below the MySqlCommand constructor.
As I said, it's sorted now, the problem was the connection string addressing "localhost" instead of "mysql.x10hosting"

Code:
  hookUp = newMySqlConnection(strConnect);
  DataOutput.Text += "Connected<br/>";
  sqlCmd = newMySqlCommand(strFilter, hookUp);
  DataOutput.Text += "Command created<br/>";
  hookUp.Open();
 

xav0989

Community Public Relation
Community Support
Messages
4,467
Reaction score
95
Points
0
It's interesting, as in php I still use localhost, but in ASP.net you seem to need to user mysql.x10hosting.com
 

thegriff

New Member
Messages
14
Reaction score
0
Points
0
Mmm. It is all a little odd:

php @ x10 = localhost
asp.net @ x10 = myqsl.x10
local machine asp.net mySQL = localhost
local machine asp.net SQL = GRIFF\\SQLEXPRESS

Go figure...:nuts:

It's simple enough when you know what to use, but working it out from scratch is a real PITA!
 
Last edited:
Top