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.
Related
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?
guys i'm trying to develop an app (using vb.net & sql database) ,managing my database using PhpMyAdmin ,so the problem is , when executing my app , it shows nothing :/ , i don't know if the problem is a bad password , but even so , it should be showing me a error message (i used catch nd try ...)
> the code !
Imports System.Data.SqlClient
Module Module1
Sub Main()
Dim Connexion As New SqlConnection("Data Source=localhost;Initial Catalog=stockage;User Id=pma;Password=pmapass;")
Try
Connexion.Open()
Dim Requete As String = "UPDATE client SET nom_client ='client unknown' WHERE nom_client is null"
Dim Commande As New SqlCommand(Requete, Connexion)
Try
Console.WriteLine("there was " & Commande.ExecuteNonQuery() & " lignes changed")
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
Commande.Dispose()
Connexion.Close()
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
Console.ReadLine()
End Sub
End Module
(when executing the console it shows nothing )
thanks !
First of all you're not managing a SQL Database with phpMyAdmin. phpMyAdmin manages mySQL databases instead.
Secondly you need to install Connector/Net through this link
Note : Please go for version 6.6.7 as they have removed Visual
Studio integration from 6.7.7 and above
Once the connector is installed, start a new project in VB.NET (Im using 2008) and you will then need to add a reference to the connector.
Choose "Add Reference" from the Project menu, then select "Browse" and browse to the installation folder where the connector was installed,
choose "MySQL.Data.dll" .
Imports MySql.Data.MySqlClient 'Very Important
Module Module1
Sub Main()
Dim Connexion As New MySqlConnection
Dim db_name As String = "stockage"
Dim db_host As String = "localhost"
Dim db_username As String = "pma"
Dim db_password As String = "pmapass"
If Not Connexion Is Nothing Then Connexion.Close() 'to close already open connections
Connexion.ConnectionString = String.Format("server={0}; user id={1}; password={2}; database={3}; pooling=false", db_host, db_username, db_password, db_name)
Try
Connexion.Open()
Console.WriteLine("Connected to server " + db_host)
Dim Commande As MySqlCommand
Dim Requete As String = "UPDATE client SET nom_client ='client unknown' WHERE nom_client is null"
Commande = New MySqlCommand(Requete, Connexion)
Console.WriteLine("there was " & Commande.ExecuteNonQuery() & " lines changed")
Connexion.Close()
Console.WriteLine("Disconnected from server " + db_host)
Catch ex As MySqlException
MessageBox.Show("Cannot connect to database: " & ex.Message)
Finally
Connexion.Dispose()
End Try
End Sub
End Module
I am building a Windows Store application who is intended to interact with a MySql database located at a server in my local network.
I am using MySQL connector/net RT to connect(which works on my testing localhost DB), the problem is that for some reason i cannot connect to the network database; although i can get a successful connection with a different Win32 app, who has the same connection string.
i disabled the firewall, i created a new user on the host to access from my AP, etc. Can somebody tell me what am I doing wrong?
C#
using MySQL.Data.MySqlClient;
using Windows.UI.Popups;
MySqlConnection connection = new MySqlConnection("server=1.1.1.1;port=3306;database=mydb;uid=user;password=****;");
try{
connection.Open();
connection.Close();
}
catch (MySqlException e){
MessageDialog md = new MessageDialog(e.ToString());
md.ShowAsync();
}
//Exception:
failed to Open Connection
This is how I connect. Hope it Helps
Imports MySql.Data.MySqlClient
Public Class ClassMySqlConnect
Public Shared SQLConnect As String = "Server=YOURSERVERADDRESS; User Id=YOURID; Password=YOURPASSWORD;Database=YOURDATABASENAME"
Public Function connect(ByVal PlayerID As String) As String
Dim SQLConnection = New MySqlConnection
SQLConnection.ConnectionString = SQLConnect
Try
If SQLConnection.State = ConnectionState.Closed Then
SQLConnection.Open()
'Return "Sucessfully Connected to MySql Database"
Else
SQLConnection.Open()
' Return "Connection is closed"
End If
Catch ex As Exception
' Return ex.ToString()
End Try
Dim SQLStatement As String = "INSERT INTO Toons (PlayerID) Values('" + PlayerID + "')"
Dim cmd As New MySqlCommand
With cmd
.CommandText = SQLStatement
.CommandType = CommandType.Text
.Connection = SQLConnection
.ExecuteNonQuery()
End With
Return "successfully saved"
End Function
End Class