Firstly, as far as I know sharing the username/password should NOT be done as I'm attempting to make a user register/login program. My server is remote, so I connect to it with an IP address. I have been trying for a very long time but I always run into errors.
Even when providing the MySQL Username and password, it fails entirely.
Some stuff I've tried:
Dim connection As New MySqlConnection("datasource=(ip);port=22;username=root;password=(pwd);database=(db)")
Dim connection As New MySqlConnection("datasource=(ip);port=3306;username=root;password=(pwd);database=(db)")
Dim connection As New MySqlConnection("server=(ip);port=22;username=root;password=(pwd);database=(db)")
And then I realised another thing about my server, I require the SSH option when connecting so I tried this. However I still encounter the same errors on opening the MySQLConnection (portFwld.Start & Client.Connect is successful)
Dim ConnectionInfo = New PasswordConnectionInfo("(IP)", "root", "(PWD)")
Dim ConString = New MySqlConnectionStringBuilder
ConnectionInfo.Timeout = TimeSpan.FromSeconds(7)
Dim client = New SshClient(ConnectionInfo)
client.Connect()
Dim portFwld = New ForwardedPortLocal("127.0.0.1", Convert.ToUInt32("3306"), "(IP)", Convert.ToUInt32("22"))
client.AddForwardedPort(portFwld)
portFwld.Start()
ConString.Server = "(IP)"
ConString.Port = "22"
ConString.UserID = "root"
ConString.Password = "(PWD)"
ConString.Database = "(DB)"
Dim Connection = New MySqlConnection(ConString.ToString)
Connection.Open()
The errors I encountered were mostly these:
{"Reading from the stream has failed."}
and:
{"Unable to connect to any of the specified MySQL hosts."}
I literally have no idea why nothing is working whatsoever. I've searched and searched and I cannot find the solution. Also a reminder; I'm pretty sure I don't want the password revealed so blatantly in a string, let alone revealed at all.
Please be considerate as I'm completely new to this and just want to setup a community program just like any other program/site (like accounts here on Stackoverflow).
Thanks in advance.
The issue was that I needed to go to my server's cPanel and go to the allowed IPs area and add %, after that connection was all successful.
Related
[Connection String I need help with]
I am a newbie and I just learned this online. I was able to complete a project with a working connection to an MS Access database that is not encrypted. Now, I have to put password on the database as requested by the users and because of that, my connection is no longer working. So I also updated the connection string (The one in the picture). I am trying to complete this string but I do not know how to put that "Options as Long = -1". Just to add to the context, If I do not complete that string, "I am getting error 13 Type mismatch on import data", so I kinda figured out that that string should be completed and that option should be defined as long in order to get through the type mismatch. If there is also another way to this, I would be glad to learn. Appreciate any help. Thanks.
I tried just putting option: long, or options: long =-1, nothings working.
Your code is not correct.
You can try the following code to open the connection
cnn.ConnectionString = "Provider=Microsoft.Ace.OLEDB.12.0;Data Source=" & dbPath & ";Mode=Share Deny None;Jet OLEDB:Database Password=testpassword"
cnn.Open
Dim dt As New DataTable
With dt
.Columns.Add("Itemname")
.Columns.Add("Quantity")
.Columns.Add("Price")
.Columns.Add("Total")
End With
For Each dr As DataGridViewRow In Me.DataGridView1.Rows
dt.Rows.Add(dr.Cells("Itemname").Value, dr.Cells("Quantity").Value, dr.Cells("Price").Value, dr.Cells("Total").Value)
Next
Dim rptdoc As CrystalDecisions.CrystalReports.Engine.ReportDocument
rptdoc = New ordersprint
rptdoc.SetDataSource(dt)
can somebody help me with this ? here's my code in printing the data in datagridview ?
Failed to load database is when your VB.net is not able to connect to database itself. The query execution comes later. Check if connection string is proper and MySQL db is able to listen to connection request from outside localhost.
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 have been working on a project that is near completion but this final part is causing me some headaches because I have never done this before and I am having a hard time finding the research to help get me going I have no idea where to even begin. The project is as follows: (this is the context of the email from my boss)
You will need to look up how to check for connectivity using vba. The server you will connect to is the HRLearnDev. I have an access form I will send you that has the connection info in macros on it, where I did something similar. The difference is, my program connected directly to the server. Yours will need to write to a local table, do a check for connectivity when the access file is opened, or every few minutes or something, and if the check reads that there is a connection, write the data from the local server table to the remote server table, then truncate the local table.
I am really stuck and I am running out of options so any insight on where to start to look that is for beginners would be greatly appreciated.
Try something like this to check the connection:
Public Sub TestConnection()
Dim cnn As ADODB.Connection
Dim canConnect As Boolean
Set cnn = New ADODB.Connection
cnn.Provider = "sqloledb"
cnn.Open "Data Source=HRLearnDev;Initial Catalog=YourTableName;UserID=userID;Password='password';"
If cnn.State = adStateOpen Then
canConnect = True
cnn.Close
End If
MsgBox "Can you connect? - " & canConnect
End Sub
Honestly, this is obviously a homework problem and I don't think giving you the entire answer would be the right thing to do, but that should get you started.
Hi
I have some VBA code which first connects to a MySQL database in remote server, then it queries it.
Sometimes the MySQL database is not available (server down, internet connection problem, etc) but the connecting VBA code (see code below, 2nd line) goes on for minutes, which is rather frustrating for the user.
...
Set oConn = New ADODB.Connection
oConn.Open connection_string
...
Is there a way to stop after, say 25 seconds with VBA so a message can be displayed like "Server seems to be down. Please contact your system admin" ?
Thanks in advance for your help
You can use ADODB.Connection's ConnectionTimeout property:
Set oConn = New ADODB.Connection
oConn.ConnectionTimeout = 25
oConn.Open connection_string