NullReferenceException when trying to connect to MySQL with Windows authentication

567 Views Asked by At

I'm trying to connect to a local MySQL database using Windows authentication (integrated security). I use the following connection string:

server=localhost;database=mydatabase;integratedsecurity=True

On MySqlConnection.Open() I get a `NullReferenceException from somewhere deep inside. Here is the stack trace:

at MySql.Data.MySqlClient.Authentication.MySqlNativePasswordPlugin.MoreData(Byte[] data)
at MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.AuthenticationChange()
at MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.HandleAuthChange(MySqlPacket packet)
at MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.Authenticate(Boolean reset)
at MySql.Data.MySqlClient.NativeDriver.Authenticate(String authMethod, Boolean reset)
at MySql.Data.MySqlClient.NativeDriver.Open()
at MySql.Data.MySqlClient.Driver.Open()
at MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings)
at MySql.Data.MySqlClient.MySqlPool.CreateNewPooledConnection()
at MySql.Data.MySqlClient.MySqlPool.GetPooledConnection()
at MySql.Data.MySqlClient.MySqlPool.TryToGetDriver()
at MySql.Data.MySqlClient.MySqlPool.GetConnection()
at MySql.Data.MySqlClient.MySqlConnection.Open()

Some details about my setup:

  • Windows 10 x64
  • MySQL Server 5.7.16 x64
  • Connector/NET 6.9.9 x86
  • C# with Visual Studio 2015, targeted to .Net Framework 4.5.2

Is this a bug in the server or in the connector? Or do I have an error in my connection string?

2

There are 2 best solutions below

0
On BEST ANSWER

Windows authentication needs Windows Native Authentication Plugin to be installed and enabled. And this feature only available on their commercial (enterprise) edition. If you are using the community version, it seems that you cannot use this feature and use standard connection string:

server=server_address;uid=user_id;pwd=password;port=mysql_port;database=your_database
0
On

Use your ip address when define server. Without using localhost.

connstr=[ip adress];database=mydatabase;uid=[uid];password=[password];
integratedsecurity=True

MySqlConnection conn=new MySqlConnection(connstr);