Hi all I'm having trouble with regards to opening my connection on my mysql database on xampp. I'm not quite sure about the issue here. But please do correct me if I'm wrong, is there a problem with my connectionstring script or does Visual Studio 2019 handle it differently now compared to it's previous versions. I've tried removing the "con.Open()" line. but the problem with this is I can't seem to even be able to insert some data into my databse without the "con.Open()" line
here's the code by the way.
Module Module1
Public con As New MySqlConnection
Public cmd As New MySqlCommand
Sub openCon()
con.ConnectionString = "server=localhost; username=admin; password=; database=db_tutorial"
con.Open()
End Sub
End Module
here's an image of the error by the way.
Related
Look, I'm working and doing tests with Access databases in Visual Basic.
I created an access database, and place it in the bin / debug folder of the project. Without assigning a password , it connects sucesfully with the database ... but when I encrypt the database (or put a password to the database with exclusively mode), my connection fails:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim tabla As DataTable = New DataTable
Dim ds As DataSet = New DataSet
Dim conexion As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=soq.accdb;Persist Security Info=False;Jet OLEDB:Database Password=mypassword;")
Try
conexion.Open()
MsgBox("Estoy operando.")
Catch ex As Exception
MsgBox("No ando haciendo eso")
End Try
conexion.Close()
End Sub
Whats the problem here?? I wrote something wrong??? (I got Microsoft Access 2013)
Okay guys, i found the solution!
The encryption method of Microsoft Access 2013 dont works properly. So my solution was simple: Use the encryption method of the 2007 version, and done!
Thanks all!
I have spent the last 2 years writing a bit of code which is working great at home but when I try and run it at work the network policies do not allow it.
It reads and writes to the following IP: "196.30.221.209"
http://196.30.221.209/phpmyadmin
My IT guys at work can’t get it to allow
Any suggestions. (port No. etc)
Im sure you had this question before
At home and other wifi areas its perfect.
With the following code:
Try
Dim PHPDB As String = "196.30.221.209"
Dim con As MySqlConnection = New MySqlConnection("Data Source=" + PHPDB + ";Database=####;User ID=####;Password=####;")
Dim ds As DataSet = New DataSet()
Dim DataAdapter1 As MySqlDataAdapter = New MySqlDataAdapter()
Dim sql As MySqlCommand = New MySqlCommand("SELECT * FROM TEST_DB ", con)
con.Open()
DataAdapter1.SelectCommand = sql
DataAdapter1.Fill(ds, "TEST_DB")
DGV1.DataSource = ds.Tables(0)
con.Close()
Catch
End Try
Thanks a mill Guys
Well I can access it so you will need to talk to your IT guys. There isn't anything we can really tell you unless you be a lot more specific in what you've tried. I'm sure your work have port 80 unblocked...
What do you see when you try and access it at work? What other details do you have? Can you access another phpmyadmin server? Have you tried reinstalling phpmyadmin?
I'm having a great deal of trouble finding code examples to connect a VB.net client application I am writing to a MYSQL5 database. I am trying to access a database I created through WAMP and phpMyAdmin.
where on the internet is a simple example of a programmatic implementation of an object I can use to connect these two seemingly un-connectable entities?
Just to make it a bit clearer:
I have a DB made through phpMyAdmin called: test
within the db is a table: sys_users
within the table are: user_ID (pk), user_name, user_password
simply looking to connect VB.net to test and query the table sys_users, returning a boolean if they exist. From there, I can figure out the rest of my solution for my program dealing with other tables and data.
thanks for any help in this.
Imports MySql.Data.MySqlClient
Imports System.Data.SqlClient
Public Class login
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim strConStr As String = "Data Source=localhost;uid=********;pwd=********;database=********"
Dim conn As MySqlConnection
conn = New MySqlConnection(strConStr)
MsgBox(conn.ConnectionString.ToString)
Try
conn.Open()
MessageBox.Show("Connection Opened Successfully")
conn.Close()
Catch myerror As MySqlException
MessageBox.Show("Error Connecting to Database: " & myerror.Message)
Finally
conn.Dispose()
End Try
End Sub
End Class
Yes, this was a problem for someone else, but the solution seems to work so far. As for the Password validation etc, I will most definitely make use of it. All I needed guys, thanks.
My boyfriend and I have spent the last 2 hours trying to get this to work, we have tried putting all the data connections into try's, changing the the connections to gloabal's but whatever we do we end up back at the same problem. The page will load fine when loaded via localhost, but when we try to get in via debug it hits this error.
If we put the code that fails into a try it goes through each connection and then will load, but each part will have been caught in the catch.
An exception of type 'MySql.Data.MySqlClient.MySqlException' occurred in MySql.Data.dll but was not handled in user code
There is already an open DataReader associated with this Connection which must be closed first.
Here's the code, each sub or function that uses MySQL connection has a close in the same as this function. We are out of ideas to what it causing it, as only does it we try and enter debug in Visual Studio.
Public Function getID()
Dim cmd As New MySqlCommand()
Dim reader As MySqlDataReader
Dim rtr As Integer
cmd.CommandText = "MySQLSTATEMENT"
cmd.Connection = CON_STRING
Connection.Open()
reader = cmd.ExecuteReader
If (reader.HasRows()) Then
reader.Read()
rowID = reader.Item(0)
End If
Connection.Close()
reader.Close()
cmd.Dispose()
End Function
You Should Close reader first and then you can close the connection.
I would recommend Using Statement for connection that will take care of closings the connection.
I have a project in Visual Studio 2008 and there is a working data connection to a MySQL database. In other words, I can query the db directly from Visual Studio and it will display the results.
I've tried a couple of approaches that I found online for writing a connection string and accessing the db, but no luck yet.
All I'm trying to do is code a button to query the db and then reset the text property of a label/textbox to display the results based upon another label/textbox value.
The pseudo-code I am imagining is something like this:
Private Sub query_submit_button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles query_submit_button.Click
result_textbox.Text = SELECT field FROM table WHERE otherfield = key_textbox.Text
End Sub
I didn't see any related questions posted on SO - forgive me if I missed one that already exists and this is a dupe.
What is the correct way to accomplish this?
EDIT
Using MySQL 5.1
You can download the ODBC Provider and then reference, import, and use it to query the database through a ODBCCommand instance.
'Put this at the very top of your .VB file...
Imports System.Data.ODBC
'Put this in some method in your code when you are ready to query the DB...
Using connection As New OdbcConnection(connectionString)
Dim command As New OdbcCommand(strSqlQuery, connection)
connection.Open()
result_textbox.Text = command.ExecuteScalar.ToString
End Using
i used DaMartyr's answer to get 99% there, but needed to add this declaration:
Dim connectionString As String = "driver={MySQL ODBC 5.1 Driver};server=SERVER;uid=USERID;pwd=PASSWORD;database=DATABASE"
just replace the SERVER, USERID, PASSWORD, & DATABASE with your personal settings