MySQL <-> VB.net issues

new_future

New Member
Messages
8
Reaction score
0
Points
0
Hello everyone,

I'm trying to set a connection between my vb.net application and my MySQL located on mysql-starka.x10hosting.com
The issue is, that I can't seem to find a good tutorial explaining it, and if i do, he asks me for IP, port etc. which I don't have (or see on the phpmyadmin).

If anyone knows how to do it, please respond a.s.a.p. since I really need it.

Yours sincerely, Anasky.
 

thegriff

New Member
Messages
14
Reaction score
0
Points
0
Tutorials do seem a bit useless - I had to work out most of it myself, with bits of google everywhere.

You have the mySql address, which is good: mysql-starka.x10hosting.com but it won't work - see later under web.config!

Have you got the mySql Connector? (the bit that comes in two ASP.NET assemblies mysql.Data.dll and mysql.web.dll) If so, then copy the two DLLs to the "/public_html/bin" folder in your webspace.

Have you set up a database in phpMyAdmin? If not, create a simple on for testing.

Have you set up a user for your databases, and allowed them full access rights to your test database? (phpMyAdmin again).

Edit your web.config on the server, and make it look lijke this:
Code:
<?xml version="1.0" ?>
<configuration>
  <appSettings />
  <connectionStrings>
    <add name="LoginDatabase" connectionString="server=mysql-chopin.x10hosting.com;database=XXX_testing;user id=DATABASEUSER;password=PASSWORD"/>
  </connectionStrings>
  <system.web>
    <customErrors mode="Off" />
  </system.web>
  <system.net>
    <mailSettings>
      <smtp deliveryMethod="network">
        <network port="26" />
      </smtp>
    </mailSettings>
  </system.net>
</configuration>

Replace the XXX with your x10hosting userid - I am guessing "starka", replace the DATABASEUSER and PASSWORD with the user info you set up in phpMyAdmin

The following code is C#, but it should be easy to translate to VB:
Code:
[SIZE=2]
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]string[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] strConnect = ConfigurationManager.ConnectionStrings[[/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"LoginDatabase"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]].ConnectionString;
MySqlCommand cmd = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] MySqlCommand([/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"SELECT Role FROM UserInfo[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515] WHERE userID = @ID"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);
cmd.Parameters.AddWithValue([/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"@ID"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], userId);
MySqlDataReader reader = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]null[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]try
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]{
cmd.Connection = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] MySqlConnection(strConnect);
cmd.Connection.Open();
reader = cmd.ExecuteReader();
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] (reader.Read())
{
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]this[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].role = (UserRole)reader[[/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"Role"[/COLOR][/SIZE][/COLOR][/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][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]throw[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]Exception[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2](cmd.CommandText + [/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"\n"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] +
ex.Message, ex);
}
[/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])
{
reader.Close();
}
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] (cmd.Connection != [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]null[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2])
{
cmd.Connection.Close();
}
}
[/SIZE]
This is lifted directly from a working routine, so it should be fine.

Make sure you have installed mySQl on your development machine, and set the connection string in the local web.config to select that (probably via "localhost" rather than "mysql-chopin.x10...")

Any probs, let me know!
 

xav0989

Community Public Relation
Community Support
Messages
4,467
Reaction score
95
Points
0
Simply to add some to the previous post, for the database creation, do not use phpmyadmin, but go directly through cPanel. As for the database username, use cPanel-username_database-username
 
Top