I’m having trouble connectiong to MySQL Server database and get the following error:
Error Message
Login failed for user ‘root’. Reason: Not associated with a trusted SQL Server connection.
This is the code where the error occurred:
public bool IsValid(string username, string password)
{
using (var con = new SqlConnection("Server=localhost;Database = timekeeping; Uid = root; Pwd = admin;"))
using (var cmd = con.CreateCommand())
{
con.Open();
cmd.CommandText = "SELECT count(*) FROM receptionist WHERE username = @username AND password = @password;";
cmd.Parameters.AddWithValue("@username", username);
cmd.Parameters.AddWithValue("@password", password);
var count = (long)cmd.ExecuteScalar();
return count > 0;
}
}
Screenshot:

This is my config file:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="ODBCDriver" value="Driver={MySQL ODBC 5.1 Driver};Server=localhost;Database=timekeeping;uid=root;pwd=admin;Option=3;"/>
</appSettings>
<connectionStrings>
<add name="connStr" connectionString="Database=timekeeping;uid=root;pwd=admin;Option=3;" />
</connectionStrings>
</configuration>
Are you using MySQL? The error message clearly states it’s Not associated with a trusted SQL Server connection. I also see you’re using SqlConnection (which then implies in SqlCommand, SqlDataAdapter, SqlDataReader and so on) which comes from the System.Data.SqlClient namespace – which is specific for SQL Server: http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.aspx (Represents an open connection to a SQL Server database.).
To connect to your MySQL database from .NET, you can use ODBC (there may be other options) or if you want to stick to ADO.NET, you can use the MySQL Connector.
I guess this should solve it for you. If I’m not mistaken, the Namespace would then be MySql.Data.MySqlClient and the classes would be named MySqlConnection and so on. Not sure about the actual prefixes, namespaces or naming though – on a Mac at the moment. No .NET here 😀