I have a problem with my code, I want to connect to my mysql glpi database but I have a launch error.
[This is a log of mysql base of glpi]
'Charger Liste'
ConnectionString = "server=10.14.242.190;port=3307;userid=root;database=GLPI;"
Dim conn As New MySqlConnection
conn.ConnectionString = ConnectionString
conn.Open()
Dim Query As String
Query = "SELECT * FROM glpi_computers"
MessageBox.Show(Query)
End If
End Sub
This is error : MySql.Data.MySqlClient.MySqlException : 'Unable to connect to any of the specified MySQL hosts.'
Related
I have this code here:
Sub Example()
Dim Conn As New Connection
Conn.ConnectionString = "Server=localhost;Port=3306;Database=testing;Uid=root;Pwd=test;"
Conn.Open
Dim rs As New Recordset
Dim sql As String
sql = "Select productcode from labels" 'put spec of desired table here
rs.Open sql, Conn
If Not rs.EOF Then
Range("a1").CopyFromRecordset rs
End If
rs.Close
Set rs = Nothing
Conn.Close
Set Conn = Nothing
End Sub
And get this error code:
run-time error -2147467259 (80004005)
How can I fix this? What I am trying to do is:
Export data from MYSQL to excel without using the add-in.
I needed to update ConnectionString with the valid Server, Database, User ID and password, as I'm using SQL server on my side.
Now, if I pause your code at sql = "Select productcode from labels" line and run it, the code will fail, highlight ConnectionString line and return the following error message:
Following the error message, I needed to specify the default driver to make the code run properly. In my case it looked like this:
Conn.ConnectionString = "Driver={SQL Server};Server=...
As you are using MySQL, I suggest trying one of the following (check ODBC version):
Driver={MySQL ODBC 5.2 UNICODE Driver};
Driver={MySQL ODBC 5.2 ANSI Driver};
I am working on to connect my App form VB.Net with MySQL table database with this code:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim str As String = "data source=localhost;Initial Catalog=tabledb;user id=root;password=password1234"
Dim con As New SqlConnection(str)
con.Open()
Dim com As String = "Select * from springdata where rfid_tag='" & Rfid_tagTextBox.Text & "'"
Dim cm As New SqlCommand(com, con)
Dim rd As SqlDataReader = cm.ExecuteReader()
If rd.Read() = True Then
MessageBox.Show("Valid username and password")
Else
MessageBox.Show("Invalid username and password", caption:="login")
End If
End Sub
But when I run the app gave me this error:
Additional information: A network-related or instance-specific error
occurred while establishing a connection to SQL Server. The server
was not found or was not accessible. Verify that the instance name
is correct and that SQL Server is configured to allow remote
connections. (provider: Named Pipes Provider, error: 40 - Could not
open a connection to SQL Server)
What is the correct ConnectionString to use with MySQL 5.7.
The connection string below is an SQL Server connection string:
Dim str As String = "data source=localhost;Initial Catalog=tabledb;user id=root;password=password1234"
According to MySQL Connector .NET connection string, you should provide server name, port number (if using different port), database name and credentials like this:
Dim str As String = "Server=localhost;Port=3306;Database=tabledb;Uid=root;Pwd=password1234"
Also you should use MySqlConnection, MySqlCommand & MySqlDataReader instances with parameters instead of value concatenation inside query string (ensure that reference to MySql.Data.dll added first):
Using con As New MySqlConnection(str)
con.Open()
Dim com As String = "Select * from springdata where rfid_tag=#tag"
Using cm As New MySqlCommand(com, con)
cm.Parameters.Add("#tag", MySqlDbType.VarChar).Value = Rfid_tagTextBox.Text
Dim rd As MySqlDataReader = cm.ExecuteReader()
' Check if any rows exist
If rd.HasRows = True Then
' do something
Else
' do something else
End If
End Using
End Using
While using the following code to connect to my SQL database:
MySqlConnection.ConnectionString = "server=vipervenom.net.mysql; userid=vipervenom_net_userinfo; password=PASSGOESHERE; database=vipervenom_net_userinfo;"
it prompts an error saying
Unable to connect to any of the specified MySQL hosts. ---> No such host is known.
I've been looking for hours to find an answer to this, but even though my host and login information is correct, it gives me that error. Take a look at the picture for login information -->
The entire source code:
MySqlConnection = New MySqlConnection
MySqlConnection.ConnectionString = "server=vipervenom.net.mysql; userid=vipervenom_net_userinfo; password=PASS GOES HERE; database=vipervenom_net_userinfo;"
Try
MySqlConnection.Open()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
Dim MyAdapter As New MySqlDataAdapter
Dim sqlquery = "SELECT * From Users WHERE email='" & TextBox1.Text & "' AND password='" & TextBox2.Text & "';"
Dim command As New MySqlCommand
command.Connection = MySqlConnection
command.CommandText = sqlquery
MyAdapter.SelectCommand = command
Dim Mydata As MySqlDataReader
Mydata = command.ExecuteReader
If Mydata.HasRows = 0 Then
MsgBox("Wrong login information!")
Else
MsgBox("Login Successful! :D")
End If
Thank you in advance!
For what it's worth, vipervenom.net.mysql is not, and cannot be, a valid hostname, your hosting provider's statements to the contrary notwithstanding.
There aren't any hostnames ending in .mysql because that is not a valid top level domain name.
It's possible your hosting provider has an internal domain naming service handling .mysql as a TLD. But you won't be able to use that hostname from outside their network.
Ask your hosting provider what hostname to use for your MySQL server from outside their network.
i want to connect with mysql phpmyadmin database and get data in my application in vb.net but i can not connect.i got error message that unable to connect with specified host.
when i entered 10.1.1.53/phpmyadmin in my browser i am able to open my all database without any password or username but when i try to connect with my vb.net application by clicking button i got error message.
this is my code. please help me.
ImportsMySql.Data.MySqlClient
PublicClasslogin
Dim con AsMySqlConnection
Dim reader AsMySqlDataReader
Dim command AsMySqlCommand
DimmyconAsString = "server=10.1.1.53/phpmyadmin;database=dbtest"
PrivateSubbtnlogin_Click(sender AsObject, e AsEventArgs) Handlesbtnlogin.Click
login()
EndSub
PrivateSublogin()
con = NewMySqlConnection
con.ConnectionString = mycon
Try
con.Open()
Catch ex As Exception
EndTry
EndSub
PrivateSubbtnexit_Click(sender AsObject, e AsEventArgs) Handlesbtnexit.Click
Me.Close()
EndSub
EndClass
Public Sub login()
Dim DatabaseName As String = "dbtest"
Dim server As String = "10.1.1.53"
Dim userName As String = "username"
Dim password1 As String = "pass"
If Not conn Is Nothing Then conn.Close()
conn.ConnectionString = String.Format("server={0}; user id={1}; password={2}; database={3}; pooling=false", server, userName, password1, DatabaseName)
Try
conn.Open()
' MsgBox("Connected")
Catch ex As Exception
MsgBox(ex.Message)
End Try
'conn.Close()
End Sub
the one that u gave me is DimmyconAsString << is that typo?
I developed a project in VB.NET
In this project I want to use data from MySQL that is resides in my WEB Server.
I can communicate with the MySQL server of my localhost but can not communicate with the WEB Server.
In my CPanel I added Host from the Remote Database Access
But I can't communicate with WEB MySQL Server.
Please help me.
Dim connection As MySqlConnection
connection = New MySqlConnection()
connection.ConnectionString = "Server=saver ip; Port=2082; Uid=username; Pwd=password; Database=database; Connect Timeout=60;"
Try
connection.Open()
MessageBox.Show("Connection Opened Successfully")
connection.Close()
Catch mysql_error As MySqlException
MessageBox.Show("Error Connecting to Database: " & mysql_error.Message)
Finally
connection.Dispose()
End Try
When i try to run this. I got this error "Error Connecting to Database: Reading from the stream has failed."
Note*: My database name like "myweb_dbname" and my user name "myweb_username" is this ok? i am using cPanal1.0 (RC1) and mysql5.1.56-log and os linux.
Jeff V : Thank you! When i try your code..
Dim dataConnection As New MySql.Data.MySqlClient.MySqlConnection()
dataConnection.ConnectionString = "Server = xx.xx.xxx.xxx; Database = dbNAME; Uid = userID; Pwd = password;"
Dim dataCommand As MySql.Data.MySqlClient.MySqlCommand = New MySqlCommand()
dataCommand.Connection = dataConnection
Try
dataConnection.Open()
dataConnection.Close()
Catch x As Exception
Console.WriteLine(x.Message.ToString())
MsgBox(x.ToString)
End Try
I Get this error message:
MySql.Data.MySqlClient.MySqlException: Unable to connect to any of the
specified MySQL hosts. at
MySql.Data.MySqlClient.NativeDriver.Open() at
MySql.Data.MySqlClient.Driver.Open() at
MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder
settings) at
MySql.Data.MySqlClient.MySqlPool.CreateNewPooledConnection() at
MySql.Data.MySqlClient.MySqlPool.GetPooledConnection() at
MySql.Data.MySqlClient.MySqlPool.TryToGetDriver() at
MySql.Data.MySqlClient.MySqlPool.GetConnection() at
MySql.Data.MySqlClient.MySqlConnection.Open() at
mysql.Form1.Button3_Click(Object sender, EventArgs e) in
C:\Users\pram\Documents\Visual Studio
2008\Projects\mysql\mysql\Form1.vb:line 48
In line 48 "dataConnection.Open()"
I am not sure about what is going on down there, but if this is MSSQL, I would normally check with protocols, firewall
try this one. I am using this snippet to execute commands.
Imports MySql.Data.MySqlClient
Dim strConnString As String = "server=xxx.x.x.x;uid=user;pwd=password;database=xxx"
Dim objConn As New MySqlConnection(strConnString)
Public Function MyDataSet(ByVal strSQL As String) As DataSet
Dim ds As New DataSet
Dim mycmd As MySqlCommand = New MySqlCommand(strSQL, objConn)
Dim ad As MySqlDataAdapter = New MySqlDataAdapter
ad.SelectCommand = mycmd
objConn.Open()
ad.Fill(ds, "a")
objConn.Close()
Return ds
End Function
Best Regards,
#iamsupergrasya
This is how I did it (using C#):
using System.Data.Sql;
using MySql.Data.MySqlClient;
MySql.Data.MySqlClient.MySqlConnection dataConnection = new MySql.Data.MySqlClient.MySqlConnection();
dataConnection.ConnectionString = "Server = xx.xx.xxx.xxx; Database = dbNAME; Uid = userID; Pwd = password;";
MySql.Data.MySqlClient.MySqlCommand dataCommand = new MySqlCommand();
dataCommand.Connection = dataConnection;
//tell the compiler and database that we're using parameters (thus the #first, #last, #nick)
dataCommand.CommandText = ("INSERT INTO ...;");
//add our parameters to our command object
dataCommand.Parameters.AddWithValue("#recordId", dataString[0].ToString());
...
try{
dataConnection.Open();
dataCommand.ExecuteNonQuery();
dataConnection.Close();
}catch (Exception x){
Console.WriteLine(x.Message.ToString());
}
I thought I might of had it originally in VB.Net but you "should" be able to convert this to VB fairly easily. If you still need help let me know. I will try to convert it tonight.
Let me know if it works for you.
UPDATE - VB.NET Code:
Dim dataConnection As New MySql.Data.MySqlClient.MySqlConnection()
dataConnection.ConnectionString = "Server = xx.xx.xxx.xxx; Database = dbNAME; Uid = userID; Pwd = password;"
Dim dataCommand As MySql.Data.MySqlClient.MySqlCommand = New MySqlCommand()
dataCommand.Connection = dataConnection
'tell the compiler and database that we're using parameters (thus the #first, #last, #nick)
dataCommand.CommandText = ("INSERT INTO ...;")
'add our parameters to our command object
dataCommand.Parameters.AddWithValue("#recordId", dataString(0).ToString())
Try
dataConnection.Open()
dataCommand.ExecuteNonQuery()
dataConnection.Close()
Catch x As Exception
Console.WriteLine(x.Message.ToString())
End Try
I used this converter tool (http://www.developerfusion.com/tools/convert/csharp-to-vb/) - So try this out.
Update - Answer from question on comment:
you can ping your site using the command prompt:
cmd.exe
Then in the command window type in the URL of your site. That will give you back the IP address of your site.