Connecting to an external SQL database in C #

I have a SQL server and setting up a database on an external server (let me name the domain name "hello.com" for the purpose of this), and I want to connect to this server using a C # program. So far, I have this (all data about the server / database is different from the real one):

private static void SetupSQL() { string connectionString = "server=hello.com; database=db1; uid=user1; pwd=xxxxx;"; connection = new SqlConnection(); connection.ConnectionString = connectionString; try { connection.Open(); Console.WriteLine("Connected"); } catch (Exception e) { Console.WriteLine(e.Message.ToString()); } } 

This gives me an error message:

 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) 

I checked the entire connection string and I am allowed remote access, since I have SQLWorkbench opening a database query right now on the same computer.

Any ideas?

+6
source share
2 answers

You will need the MySQL driver:

http://dev.mysql.com/downloads/connector/net/

Then you can use the MySqlConnection connection MySqlConnection to connect.

 MySqlConnection connection = new MySqlConnection(connectionString); 

http://www.codeproject.com/Articles/43438/Connect-C-to-MySQL

+5
source

You cannot use the SqlConnection object to connect to the MySQL database, you must use MySqlConnection instead of importing your DLL

+3
source

Source: https://habr.com/ru/post/927451/


All Articles