2

I'm using MySql database

Here is my code:

mysqlconn = New MySqlConnection
mysqlconn.ConnectionString = "host= 192.168.1.52; server=127.0.0.1; port=3306; userid=root; password=; database=dbfsesmis"

I want to access my database from another computer what's wrong with the code above?

LecheDeCrema
  • 392
  • 5
  • 21

2 Answers2

1
mysqlconn = New MySqlConnection
mysqlconn.ConnectionString = "host= 192.168.1.52; server=127.0.0.1; port=3306; userid=root; password=; database=dbfsesmis"

while the server should be the IP/domain to your database. Let's say I am developing at 127.0.0.1 and the SQL server is located at 192.168.1.52, the connection string should be mysqlconn.ConnectionString = "server=192.168.1.52; port=3306; userid=root; password=; database=dbfsesmis"

Zay Lau
  • 1,856
  • 1
  • 10
  • 17
  • Sir please read carefully before answering. I'm using MySql database not SQL server. I've tried that but the 127.0.0.1 is my localhost. where my database is found. and the 192.168.1.52 is my PC's IPv4. – LecheDeCrema Aug 30 '16 at 03:27
  • error is : Host 'PCNAME' is not allowed to connect to this MySql Server – LecheDeCrema Aug 30 '16 at 03:31
  • You may want to take a look at http://stackoverflow.com/a/1559992/6161894 – Zay Lau Aug 30 '16 at 03:37
  • maybe i'll disregard the host and the server will remain the same, and install the system to all the pc and put the IP to the IP address of the server? what do you think? maybe it will run then. – LecheDeCrema Aug 31 '16 at 03:07
  • I suggest you could setup a minimal environment that only try to have a successful connection between .net and MySql server, I have took a look at https://www.connectionstrings.com/mysql/ and find the proper connection string of MySql/Net is `Server=myServerAddress;Port=1234;Database=myDataBase;Uid=myUsername; Pwd=myPassword;` – Zay Lau Aug 31 '16 at 03:28
0

Suppose your MySQL server is hosted on: 192.168.1.52

method 1: telnet from another pc to 192.168.1.52 and connect server to 127.0.0.1 and you do not need to change any MySQL user permissions.

Method 2: connect directly from another pc [eg 192.168.1.123] to 192.168.1.52

in this case you need to setup user permission from 192.168.1.123 or use widecat 192.168.1.%

So your host-pc: mysql.user will have a record looks like:

Host = 192.168.1.%
User = ...
...
SIDU
  • 2,258
  • 1
  • 12
  • 23
  • is my connection string correct sir? Because I will test it with another pc. I'll give my feedback after I done testing. – LecheDeCrema Aug 30 '16 at 03:28
  • never done vb.net before. but just curious why your connection string contains host and server? try google by yourself eg: https://www.connectionstrings.com/mysql-connector-net-mysqlconnection/ – SIDU Aug 30 '16 at 03:39