0

I have installed MySQL Community server on local machine and am trying to access it from .NET Core API. Something must be wrong with either the connection string or the server configurations. I have checked the server configs to make sure TCP/IP connections are allowed, checked the connection string according to tutorials but still fail to connect, getting this exception in code:

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.

Tried connecting to MSSQL database and there are no issues, so nothing else could be wrong from code-side apart from the connection string itself. The connection string:

"SqlConnectionString": "Server=127.0.0.1;Uid=admin;Pwd=admin;Database=sys;"

SQL query in code (using Dapper):

private const string SQL_INSERT_ENTITY = @"
        INSERT INTO [sys].[adminportal_restapi] (Id, FeatureName, IsEnabled, LastInsertUpdate)
        VALUES (@Id, @FeatureName, @IsEnabled, @LastInsertUpdate)
        ";

Database layout: MySQL localhost

1 Answer 1

0

Found the solution - you have to use a different connector. Basically these changes are needed: in project.json add this dependency: "MySql.Data.Core": "7.0.4-IR-191" and in code change new SqlConnection to new MySqlConnection

EDIT: that package got unlisted by MySQL devs without releasing a newer version (which is a complete douchebag move, IMO), so just use this one instead: "MySqlConnector": "0.11.5" syntax for connections is identical, just it doesn't support integrated security, which might suck in some cases. Good luck

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.