-
Oct 23rd, 2014, 08:43 AM
#1
Thread Starter
Addicted Member
[RESOLVED] Hostgator connection string ?
I created the mysql database via phpmyadmin at hostgator.com hosting .
Using mysql connector to work withdatabase and i stuck i don't know how to make a connection string ?
I'm trying like this
Code:
mysqlconnection.ConnectionString = "server=hostgator.com; Port=3306; user id=myID; password=myPW; database=myDB"
But it allways says that i cannot connect to database. Entire code downthere.
Code:
Try
mysqlconnection = New MySqlConnection
mysqlconnection.ConnectionString = "server=hostgator.com; Port=3306; user id=myID; password=myPW; database=myDB"
mysqlconnection.Open()
Catch ex As Exception
End Try
Dim sqlquiery = "SELECT id, nmbr, used, cpuid FROM teacher_keys.teacher;"
Dim command As New MySqlCommand
Dim myadapter As New MySqlDataAdapter
Try
command.Connection = mysqlconnection
command.CommandText = sqlquiery
myadapter.SelectCommand = command
myadapter.Fill(ds, "baze3")
Catch ex As Exception
MsgBox("Error! You are not connected with database.", MsgBoxStyle.Information + MsgBoxStyle.OkOnly, "Error")
End Try
-
Oct 23rd, 2014, 09:44 AM
#2
Re: Hostgator connection string ?
You'll need to get the connection information from them. A couple things to keep in mind:
* Server isn't likely to be hostgator.com, it's likely to be something else.
* you'll need to know if the db servers are behind a firewall or if they are exposed publicly to the web.
IF the db server is behind a firewall (which any respectable host will have) then you're not going to be able to directly access it from outside their network. If that's the case, you're going to need to change your approach. If the db IS open to the interwebs and you can direct connect, you just need the right connection info.
-tg
-
Oct 23rd, 2014, 10:09 AM
#3
Thread Starter
Addicted Member
Re: Hostgator connection string ?
Originally Posted by techgnome
You'll need to get the connection information from them. A couple things to keep in mind:
* Server isn't likely to be hostgator.com, it's likely to be something else.
* you'll need to know if the db servers are behind a firewall or if they are exposed publicly to the web.
IF the db server is behind a firewall (which any respectable host will have) then you're not going to be able to directly access it from outside their network. If that's the case, you're going to need to change your approach. If the db IS open to the interwebs and you can direct connect, you just need the right connection info.
-tg
Hmh to much to learn from now on. I thought it will be easy as before.
Code:
mysqlconnection.ConnectionString = "server=db4free.net;Port=3306; user id=bwun; password=bpw; database=bdb"
Connection string from db4free website.
-
Oct 23rd, 2014, 01:40 PM
#4
Thread Starter
Addicted Member
Re: Hostgator connection string ?
I contacted hostgator support they said i have those details at bottom of page.
Down there i have only
IP Address xxx.xxx.xx.xxx
Server Name gator4147
I searched a bit and when i opened one link it shown me like this
https://gator4147.hostgator.com:2083
-
Oct 23rd, 2014, 02:29 PM
#5
Re: Hostgator connection string ?
you shouldn't be getting nothing. You should be getting something... either a connection, data, or an error message. But you will get something.
-tg
-
Oct 23rd, 2014, 02:31 PM
#6
Thread Starter
Addicted Member
Re: Hostgator connection string ?
Originally Posted by techgnome
you shouldn't be getting nothing. You should be getting something... either a connection, data, or an error message. But you will get something.
-tg
always the same error
Error! You are not connected with database.
-
Oct 23rd, 2014, 02:50 PM
#7
Re: Hostgator connection string ?
That's not the error - that's your error message, but that's not the error. You should be getting a legit error message. I also notice your connection is wrapped up in a Try Catch with an empty catch... which means there could be an error happening there, but you'd never know because you chose to ignore it. What you have is the .NET equivalent of On Error Resume Next.
During development you should either 1) use try catch only very limitedly so you can see where things go wrong or 2) make sure you display meaningful messages so that you know what is wrong.
-tg
-
Oct 23rd, 2014, 03:12 PM
#8
Thread Starter
Addicted Member
Re: Hostgator connection string ?
Originally Posted by techgnome
That's not the error - that's your error message, but that's not the error. You should be getting a legit error message. I also notice your connection is wrapped up in a Try Catch with an empty catch... which means there could be an error happening there, but you'd never know because you chose to ignore it. What you have is the .NET equivalent of On Error Resume Next.
During development you should either 1) use try catch only very limitedly so you can see where things go wrong or 2) make sure you display meaningful messages so that you know what is wrong.
-tg
Thanks for your answer.
So basically i just need to test am i able to connect to a database how would i do that ???
If can't connect to a database to show me an msgbox
Code:
Dim mysqlconnection As MySqlConnection
mysqlconnection = New MySqlConnection
mysqlconnection.ConnectionString = "server=hostgator.com; Port=3306; user id=myID; password=myPW; database=myDB"
mysqlconnection.Open()
-
Oct 23rd, 2014, 03:22 PM
#9
Re: Hostgator connection string ?
That's how you would do it... make the connection... if there is an error, let it be displayed, don't cover it up with your own message... at least for now... later if you want, add in the message box.
-tg
-
Oct 23rd, 2014, 04:38 PM
#10
Thread Starter
Addicted Member
Re: Hostgator connection string ?
Originally Posted by techgnome
That's how you would do it... make the connection... if there is an error, let it be displayed, don't cover it up with your own message... at least for now... later if you want, add in the message box.
-tg
I did this code in Form Load event and it didnt show any errors :S
What am i making wrong now.
Code:
Imports MySql.Data.MySqlClient
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim mysqlconnection As MySqlConnection
mysqlconnection = New MySqlConnection
mysqlconnection.ConnectionString = "server=hostgator.com; Port=3306; user id=myID; password=myPW; database=myDB"
mysqlconnection.Open()
End Sub
End Class
-
Oct 23rd, 2014, 05:32 PM
#11
Re: Hostgator connection string ?
Yeaaah... that's another issue all together. There's a wonderful "feature" in 64-bit windows that causes exceptions to be swallowed up in the FormLoad event...
The WIndows group sees it as a feature - it prevents applications from breaking on startup. Just about everyone else in the development world sees it as a bug. It's also not going to change any time soon.
Just throw together a quick app with a button and put the code in the click event of the button.
-tg
-
Oct 24th, 2014, 04:28 AM
#12
Thread Starter
Addicted Member
Re: Hostgator connection string ?
Ok then.
It says unable to connect to mysql host
Edit: This one
{"Authentication to host 'gator4147.hostgator.com' for user 'user' using method 'mysql_native_password' failed with message: Access denied for user 'user'@'%' to database 'database'"}
-
Oct 24th, 2014, 04:39 AM
#13
Thread Starter
Addicted Member
Re: Hostgator connection string ?
Problem Solwed:
The problem was in that i created the database and the user, and i didnt assign user to that database.
Thank a lot -tg you helped me and learned that Custom messages aren't allways the right choice
-
Mar 10th, 2015, 09:41 AM
#14
Registered User
Re: [RESOLVED] Hostgator connection string ?
The problem was in that i created the database and the user, and i didnt assign user to that database.
Thanks. I think this has happened a lot on HG users as well. They may need to include this on their KB site too.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|