I'm designing a WPF form that needs to connect to a local MySQL database. I've installed mysql on my local machine and created a database, with a username and password to connect to it. See two screenshots below for more information.
My code currently looks like this:
public static bool InitialConnection()
{
try
{
using (SqlConnection con = new SqlConnection())
{
con.ConnectionString = "Server=127.0.0.1;Database=StudentTravelPlannerDB;Uid=STPUser;Pwd=CORRECT_PASSWORD;";
con.Open();
}
return true;
}
catch
{
return false;
}
}
However, when I run my WPF form, which calls this function, it always freezes for a few seconds, and the above function will return false.
Removing the try/catch statements, the application fails and gives me an error pointing to the 'con.Open()' line, stating:
"An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll
Additional information: 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)"
So what could be the problem here? My password is definitely correct. I think I laid out the connection string right, and I've tried different variants and it's always the same response, adding the port doesn't help either.
Any guidance or solutions appreciated, thank you.