nwinteractive
New Member
- Messages
- 6
- Reaction score
- 0
- Points
- 0
Ok, I have made a test database and loaded it with some data. In my test app I am trying to connect to the database but it throws a MySqlException when it hits the line of code conn.Open(). Can someone look at my code and see where I went wrong. Thanks.
VB CODE
VB CODE
Code:
Imports MySql.Data.MySqlClient
Partial Class dbtest
Inherits System.Web.UI.Page
Protected Sub Sql1Button_Click(ByVal sender As Object, ByVal e As System.EventArgs)
'Connect to database
Dim conn As MySqlConnection
Dim myData As MySqlDataReader
Dim cmd As MySqlCommand
Dim ConnectionString As String = "Server=mysql-chopin.x10hosting.com;Database=nwintera_nightwing;Uid=nwintera_test1234;Pwd=12345;"
conn = New MySqlConnection(ConnectionString)
'see if connection failed.
Try
conn.Open()
ConnLabel.Text = "Connected to databse!"
'sql query
cmd = New MySqlCommand("SELECT key FROM test WHERE key = 0", conn)
'start query
myData = cmd.ExecuteReader()
'see if key exits.
If myData.HasRows = 0 Then
MsgTextBox.Text = "Invalid Authentication Key!"
End If
Catch ex As MySqlException
ConnLabel.Text = "Error connecting to database!"
End Try
End Sub
End Class
Last edited: