简体   繁体   中英

Named Pipes Provider Error When connecting to MariaDB server on local network

I am unable to connect to my MariaDB server using C# code in a program that I am writing. The server is a CentOS machine on my local network and I am able to access the database on it from that machine as well as from other machines on the network by using ip address like this: mysql -h 192.168.0.6 -u calendar_user -p and then entering the password. Remote connections have been enabled allowing this.

However, when I try to connect in my C# code I cannot connect and I get error stating that there is "Named Pipes Provider: error 40 - Could not open a connection to SQL Server". Since I am using the same information in my connection string as I used in my other logins I am unsure of what is causing the problem. I have tried disabling windows firewall on the client machine and various different connection strings.

Currently MariaDB is running on port 3306 and the database I want to connect to is cloud_calendar with user cloud_user. I have verified the password to be correct.

Here is my connection code:

    string connectionString = @"Data Source=192.168.0.6;Initial Catalog=cloud_calendar;User ID=calendar_user;Password=" + SQL_PASSWORD + ";" ;
        Connection = new SqlConnection(connectionString);
        try
        {
            Connection.Open();
            Connection.Close();
        }catch(Exception e)
        {
            string msg = String.Format("Problem opening connection to database: {0}", e);
            MessageBox.Show(msg);
        }

As pointed out in the comments I was using the incorrect library when trying to connect. I Installed MySql for visual studio and Connector/NET and then used the nuget package manager to import the MySql.Data library. After doing this I was able to connect easily.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM