how to fix this error?vb.net - mysql

Here is the screen shot of the vb.net:
http://www.mypicx.com/12132009/ers/
And here is my code:
Dim connectionString As String = "Driver={MySQL ODBC 3.51 Driver};SERVER=localhost;DATABASE=my school;" '
Dim conn As New OdbcConnection(connectionString)
conn.Open()
Dim da As New OdbcDataAdapter("SELECT IDNUMBER, LASTNAME, FIRSTNAME, MIDDLENAME COURSE FROM students", conn)
conn.Close()
-All I want to do is to connect wamp server with vb.net, here is the version in wamp server
sql server : 5.1.36

Instead of ODBC I would suggest you downloading the ADO.NET standard driver for MySQL and use it like this:
Dim connectionString As String = "Server=localhost;Database=my school;Uid=myUsername;Pwd=myPassword;"
Using conn As New MySqlConnection(connectionString)
Using da As New MySqlDataAdapter("SELECT IDNUMBER, LASTNAME, FIRSTNAME, MIDDLENAME COURSE FROM students", conn)
conn.Open()
' Do something with the results
End Using
End Using

"Driver={MySQL ODBC 3.51 Driver};SERVER=localhost;DATABASE=my school;"
sql server : 5.1.36
You are using the wrong driver, namely one for a MySQL database. Your database is a SQL Server, so another driver is needed; try "Driver={SQL Server}" in the connection string instead (only a wild guess …).

Assuming you're using MySQL 5.1.36 and not SQL Server 5.1.36 (in which case it's really time for an upgrade) then you probably need to install MySQL Connector/NET, these are the drivers that will let you connect to a MySQL database from a .NET application.
You'll then also be able to use the native MySQL data classes, such as MySqlConnection instead of the generic OdbcConnection.

Related

Can't connect to web hosted MySQL database

I am using VB.NET to connect to a MySQL database.
I have the following code:
Public Function getListOfDatabase() As List(Of String)
Dim SQL As String = "select * from covenusers"
Dim output As New List(Of String)()
' Set the connection string in the Solutions Explorer/Properties/Settings object (double-click)
Using cn = New MySqlConnection("Server=server33.web-
hosting.com;Port=3306;Database=dbname;Uid=dbusername;
Pwd=password123;")
Using cmd = New MySqlCommand(SQL, cn)
cn.Open() 'this is where it breaks
' do stuff
End Using
End Using
Return output
End Function
I'm using Imports MySql.Data.MySqlClient for the MySQL handling. I get the exception: Unable to connect to any of the specified MySQL hosts.
I know my server address, username, database name, and password are all correct. What exactly am I connecting to here? Does it go through SSH or something else?
Apparently shared hosts do not allow you to connect to the MySQL database directly. I had to set up a SSHClient using Renci.SSHClient (google it) and port forward my database through that. What a pain smh
Hopefully this will help someone having the same issue.

MySQL - Visual Studio Express 2013 Issue

I'm having a bit of trouble trying to connect to a MySQL database through Visual Studio Express for Web 2013.
I have done a heap of reading about it and understand that its not easy for Express to connect with MySQL but it can be done manually.
I have redone a website in ASP from its Original PHP version that was done a while ago by someone else.
I have the connection string from the PHP document which reads
"DRIVER={MySQL ODBC 3.51 Driver}; SERVER=localhost; PORT=1234; DATABASE=DB; UID=root;PASSWORD=123456789; OPTION=3"
So I went to the MySQL website and downloaded the ODBC connector for version 3.51 and installed it.
In my ASP.net code I have the following to get a list of tables within the database
Dim da As MySqlDataAdapter
Dim MysqlConn As New MySqlConnection
Dim ds As New DataSet
Dim slTables As ArrayList = New ArrayList()
Dim dr As DataRow
Dim sSQL As String = "select * from information_schema.tables"
MysqlConn.ConnectionString = "SERVER=000.000.00; PORT=1234; DATABASE=DB; UID=root;PWD=123456789"
MysqlConn.Open()
da = New MySqlDataAdapter(sSQL, MysqlConn)
da.Fill(ds)
For Each dr In ds.Tables(0).Rows
slTables.Add(dr("TABLE_NAME"))
Next
MysqlConn.Close()
When trying to connect I receive an authentication error regarding the username. Seeing as its both the same in the PHP and ASP connection strings, I'm not too sure why its not working. Is it something to do with not being on the Localhost server now? (I do have the actual IP address of the server).
If that's not the issue, any pointers? I'm thinking that I have either done something wrong, or that the way i'm trying to do it still cannot be done with the express version.
I have also tried using the MySQL Connector through the control panel and receive the same error.

Do I need to install drivers to connect to remote MYSQL database from Excel 2010 via VBA?

I am trying to build an application for my team the connects to a mysql database in Excel through vba. Below is my code to connect to the mysql database but when it runs it returns the following error:
[Microsoft ODBC Driver Manager] Data source name not found and no default driver specified
Do I need to install the mysql drivers in order to attach to the db? I was hoping that I wouldn't have to have everyone install them for this to work.
Is there another way or is something wrong with my connection string?
' Create a connection object.
Dim cnFEYS As ADODB.Connection
Set cnFEYS = New ADODB.Connection
' Provide the connection string.
Dim strConn As String
'Use the SQL Server OLE DB Provider.
'strConn = "PROVIDER=MySQLProv;"
'Use the MYSQL Driver.
strConn = "DRIVER={MySQL ODBC 5.1 Driver};"
'Connect to the database on abc123.
strConn = strConn & "SERVER=abc123; DATABASE=db123;"
'Use an integrated login.
strConn = strConn & " USER=user; PASSWORD=hello; OPTION=3"
'Now open the connection.
cnFEYS.Open strConn

mysql connection string to remote server

I have access to a database on a remote mySQL server. I can read the data from my local mySQL workbench. I can also link to, and read, its tables using MS Access.
I have tried to use the following code in VB6 but are unable to establish a connection -
Set DBCon = New ADODB.Connection
DBCon.CursorLocation = adUseClient
DBCon.Open "Driver={MySQL ODBC 5.1 Driver}; Server=sherwood.unitingchurch.org.au;port=3306; Database=UCSData;User=UCS;Password=" & Pwd & ";Option=3;"
I have a copy of the mySQL database on my local computer and the VB6 program can see and use the data without problems, using the same code (but with localhost as the server).
Set DBCon = New ADODB.Connection
DBCon.CursorLocation = adUseClient
DBCon.Open "Driver={MySQL ODBC 5.1 Driver};Server=localhost; port=3306;Database=UCSData; User=UCS; Password=" & Pwd & ";Option=3;"
Any help would be appreciated.
What is the error message?
I think your problem has to do with the driver.
Which architecture(32 or 64 bits) is your Windows,Office?

Error trying to connect to MySql using DSN

It has been a long time since using VB6 and I didn't use MySql or DSN connections then, but I'm working on a legacy application that uses these. When I try to open the connect I am getting a
Data source not found and no default driver specified with this code
Dim conn As ADODB.Connection
Dim cmd As ADODB.Command
Dim rs As ADODB.Recordset
Dim sql As String
Set rs = New ADODB.Recordset
Set cmd = New ADODB.Command
Set conn = New ADODB.Connection
conn.Open "DSN=AddressHealthcheck" '<- Fails on this statement
I have also tried specifying the DSN in the conn.ConnectionString but get the same error.
The AddressHealthcheck exists in the local System DSN, uses the MySql ODBC 5.1 Driver and connects successfully when tested.
I'm sure (and hope) I missing something obvious. Any suggestions?
Thanks,
Kevin
I use a DSN-less ODBC stored in a UDL. It's basically a file with a connection string in it. Maybe the connection string will be of use. Here's an example:
[oledb]
; Everything after this line is an OLE DB initstring
Provider=MSDASQL.1;Persist Security Info=True;Extended Properties="Driver=MySQL ODBC 5.1 Driver;SERVER=mysqlsvr;UID=userid;PWD=password;DATABASE=mydatabase;PORT=3306;OPTION=18475";Initial Catalog=mydatabase
rags comment (above) wasn't the solution, but it definitely helped track it down.
When using a full connection string the error message was different and much more useful, the driver failed to load.
The issue seems to be that since I'm on a 64 bit machine it was the 64 bit driver. VB6 can't use the 64 bit driver and the 32 bit driver doesn't show up in the ODBC Connection Administrator on a 64 bit machine.
DSN is not an option in my machine.
There are two ODBC Admin tools in a 64-bit system. Run the 32-bit version. Or better yet drop ODBC and get an OLEDB Provider for MySQL.
I was researching this by 1 labour day (yesterday). Today I've realized some errors I had yesterday in order to have this working.
Dim conexion As New ADODB.Connection
conexion.ConnectionString = "DSN = yourDsnName"
conexion.open
Don't forget to...
Create a user in your mysql server that has all the priviledges you need.
Assign the server's name or ip from where it is going to connect to mysql
Create your dsn on the client machine with the correct options en test it.