Can't connect to web hosted MySQL database - mysql

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.

Related

Cannot connect to mysql database in Excel 2016 VBA

I'm trying to write a straightforward piece of code to connect to a MySQL database.
Sub DBConnection()
Dim conn As New ADODB.Connection
Dim connectionStr As String
connectionStr = "DRIVER={SQL SERVER} ;SERVER=localhost; database=sakila; uid=test1; pwd=123"
conn.Open connectionStr
conn.Close
MsgBox "Connected!"
End Sub
I am faced with this error when I run it:
I suspect the details I am providing in the connection may be incorrect but I'm not sure.
User and database name in the MySQL workbench:
Perhaps it's the server name but as I understand it being on my local machine it should be localhost.
Would appreciate any help on this, thanks!
I have the following MYSQL products installed
I have installed the 5.2 driver and followed the connection string for 5.2 from the website provided. The error is still persisting (see below). I'll keep googling but any help would be appreciated as I am very new to this.
My first stop for connection strings is connectionstrings.com, where you should e able to find a connection string that fits your MySQL version and your connection method.
The standard MySQL connection string is:
Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;
...and several others on the site for various situations.

Excel VBA to SQL Database

I've just started looking into interacting with an SQL database via Excel VBA, and I started off with the basic connection code from MSDN:
Sub GetDataFromADO()
'Declare variables'
Set objMyConn = New ADODB.Connection
Set objMyRecordset = New ADODB.Recordset
Dim strSQL As String
'Open Connection'
objMyConn.ConnectionString = "Provider=SQLOLEDB;Data Source=localhost;Initial Catalog=fatcoin;User ID=root;Password=root;"
objMyConn.Open
'Set and Excecute SQL Command'
strSQL = "select * from productlist"
'Open Recordset'
Set objMyRecordset.ActiveConnection = objMyConn
objMyRecordset.Open strSQL
'Copy Data to Excel'
ActiveSheet.Range("A1").CopyFromRecordset (objMyRecordset)
End Sub
The issue I'm having is while I have an SQL instance running on my machine, on port 3306, which I can access using for example, HeidiSQL, every time I run this code I get an error message:
[DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or access denied
I have also tried adding a port:
objMyConn.ConnectionString = "Provider=SQLOLEDB;Data Source=localhost,3306;Initial Catalog=fatcoin;User ID=root;Password=root;"
And other such things. I can't see any reason it shouldn't work, but I haven't played with this much at all. I've tried searching through other threads to no avail.
Any ideas?
I am working with Excel 2010, on a 64-bit Machine, using MySQL 5.7
I should mention the above coding is being inputted into the "Module1" section of the VBAProject on Excel.
Thanks
Thanks for the answers.
I solved my own question via a helpful link I found that suggested I go into ODBC 32-bit (because Excel is 32-bit) and create a System DSN. Then, I used the connections string below:
objMyConn.ConnectionString = "Provider=MSDASQL.1;Persist Security Info=False;User ID=root;Data Source=localhost;Initial Catalog=fatcoin"
It worked a treat.

I want to access .sql file format on the computer without using the internet

I need to access data from the database and manipulate the data. I can do this through the internet, however I need to make it so that the data can be accessed on the computer that the program runs without having internet connection.
The current method I'm using is displayed below with the code:
Dim dbDataSet2 As New DataTable
Sqlconn = New MySqlConnection
Sqlconn.ConnectionString="server=xx.xx.xx;userid=root;password=xxxxxx;database=xxxxxx"
Dim SDA As New MySqlDataAdapter
Dim bSource As New BindingSource
Try
Sqlconn.Open() 'open connection
Dim query As String
query = "SELECT * FROM bbs_test.test"
command = New MySqlCommand(query, Sqlconn)
SDA.SelectCommand = command
SDA.Fill(dbDataSet2)
bSource.DataSource = dbDataSet2
DataGridView_array.DataSource = bSource
SDA.Update(dbDataSet2)
Sqlconn.Close()
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
Is there a was to change this, so the file location is using a path like C: \ ...... or something similar
Also the file gets updated as well from time to time and the format of the file is .sql
Please can anyone help me
Thank You
The problem is likely the server address in the connection string. To make it connect to your local SQL Server engine, you can simply set the address to either (local) or ., for instance:
Sqlconn.ConnectionString="server=.;userid=root;password=xxxxxx;database=xxxxxx"
You can use local IP address of lan adapter or IP address of localhost (127.0.0.1) it work without internet connection because everything is on local computer.
You could use a local - physical database like Access.
https://kyokasuigetsu25.wordpress.com/2011/01/16/how-to-connect-ms-access-with-vb-net-using-oledb-2/

How to retrieve data from a SQL Server db

I'm writing a code snippet in VBA to pull data from a SQL Server 2008r2 database. However, I'm getting a error at Conn.Open: [Microsoft][SQL Server Native Client 10.0]Named Pipes Provider: Could not open a connection to SQL Server [53].
Using ConnectionString.com and another SO Question, I've written this:
Function GetAddress() As String
Dim Conn As ADODB.Connection
Set Conn = New ADODB.Connection
Dim Rst As ADODB.Recordset
Set Rst = New ADODB.Recordset
Conn.ConnectionString = "Provider=SQLNCLI10;Server=12.34.5678;" & _
"Database=OurDB;User ID=myuserid;Password=mypw;"
Conn.Open
Set Rst.ActiveConnection = Conn
Rst.Open "Select top 1000 * from MainTable"
End Function
Googling the error suggested that the Named Pipes might be Disabled. Following that lead, I checked the SQL Server Configuration Manager and Named Pipes are quite Enabled (3rd order behind Shared Memory and TCP/IP).
How do I make this error go away? Am I using the right connection string?
Double-check this part of your connection string:
Server=12.34.5678
It looks like referring to the server by an IP address, but it's not an IP address.

In Visual Basic, how can I see/edit tables in a remote mysql database

I'm trying to build an application so that the user can see table entries in a mysql database. I'm programming this in visual basic. How can this be done?
Include MySql connector to project, set a reference to MySql.Data.MySqlClient and create a MySqlConnection to remote host.
Example (C#):
string cstr =
String.Format("SERVER={0};PORT={1};UID={2};PWD={3}",
host, port, user, password);
MySqlConnection conn = new MySqlConnection(cstr);
VB.Net:
dim cstr as string =
String.Format("SERVER={0};PORT={1};UID={2};PWD={3}",
host, port, user, password)
dim conn as MySqlConnection = new MySqlConnection(cstr)
VB example should work...
Then you can use TableAdapters, Datasets and DataGrids to achieve your goal...