Actually, I bought a host for the site. There, through cPanel created a new SQL database.

I want to start at least to start to connect to it.

List<string> results = new List<string>(); SqlConnection conn = new SqlConnection("Data Source = myServerAddress; Initial Catalog = myDataBase; User Id = myUsername; Password = myPassword;"); using (SqlCommand command = new SqlCommand()) { command.Connection = conn; command.CommandType = CommandType.Text; command.CommandText = "Select myColumn from myTable"; using (SqlDataReader dr = command.ExecuteReader()) { while (dr.Read()) { results.Add(dr["myColumn"].ToString()); } } } 

I found this code in the same stackoverflow. Forged by itself -> issuing an error when connecting to the database.

Exception

How did I get the address: (I specified my external IP as a host) screenshot

Help! Knowledge of SQL 0, or even -1.

  • My connection string to mysql looks like this: "server=server IP; database=mydatabase; port=3306; user=myuser;" - tym32167
  • @ tym32167, Can you give the source? - icYFTL
  • give the source of what? - tym32167
  • @ tym32167, A. Everything. Got it. - icYFTL

1 answer 1

  1. Why are the variables indicated with a space? "Data Source = myServerAddress; Initial Catalog = myDataBase; User Id = myUsername;" Or is this the norm?
  2. To gain access to a remote machine, several parameters should be considered - to have a user for a remote connection. How to do it - indicated here . Also, you should configure the mysql server itself so that it listens to port 3306 not on 127.0.0.1 (localhost), but on the external interface - see the my.cnf config (the latest versions of Mysql are wrong).
    1. Check driver availability for DBMS under C #
  • Holy tambourine! Horror - icYFTL
  • If you need help, I can connect and see. - Andrei Le