Hello, i am trying to connect to mysql database remotely using C# applications (code is below). However i will always get error on connection.Open() -> server could not be found. I tryed to connect to database localy from web and that worked fine. In remote access in Cpanel i wrote just % (i did not understand that very well). I tryed to change server from Stevie.heliohost.org to IP with port but did not work
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace Databaza
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
//
}
private void button1_Click(object sender, EventArgs e)
{
Dataconnect bublatanka = new Dataconnect();
bublatanka.ConnectToDatabase();
}
}
class Dataconnect
{
public void ConnectToDatabase()
{
int id = 2;
string meno = "Hallder";
int pocet = 2500;
string db = "server = 65.19.143.2:3306; database = rhonin_da; uid = rhonin_da; password = **********"; ;
using (SqlConnection connection = new SqlConnection(db))
{
using (SqlCommand command = new SqlCommand("INSERT INTO Suroviny (ID, Meno, Suroviny) VALUES (@id, @meno, @pocet", connection))
{
command.Parameters.Add(new SqlParameter("id", id));
command.Parameters.Add(new SqlParameter("meno", meno));
command.Parameters.Add(new SqlParameter("pocet", pocet));
connection.Open();
command.ExecuteNonQuery();
}
}
}
}
}