Skip to main content

Fixed: "Option not supported (Parameter ...)" from a Semicolon in a MySQL Password in .NET C#

· 5 min read
Jagdish Kumawat
Founder @ Dewiride

Option not supported (Parameter 'def;sslmode') looked like a typo in an option name, but def was the end of my password. A ; ends a value in a connection string, so the driver read the rest of the password as a new option, and put it in the exception message. That message can end up in your logs.

What I Was Doing​

I gave a MySQL account the password abc;def, as a test of special characters, and used it as it is in a connection string, on MySql.Data 26.10.0 and .NET 10:

Connection string
Server=127.0.0.1;Port=3306;Database=inventory;User ID=quote_demo;Password=abc;def;SslMode=Required
Terminal
dotnet run test-connection.cs

What I Expected​

A connection: the password was correct.

What I Got​

Output
Unhandled exception. System.ArgumentException: Option not supported (Parameter 'def;sslmode')

The test program stopping with System.ArgumentException: Option not supported (Parameter 'def;sslmode').

What I Checked​

What's in the parameter. def;sslmode is the tail of the password, joined to the next option's name. So the parser saw Password=abc, then an option called def;sslmode, with the value Required.

Other characters. I tried each with its own account:

PasswordIn the connection stringResult
abc;defPassword=abc;defOption not supported
abc;defPassword='abc;def'Connects
abc;defPassword="abc;def"Connects
a=bPassword=a=bConnects
a bPassword=a bConnects
A space at each endNo quotesAccess denied: the spaces are dropped
A space at each endPassword=' ab 'Connects
a'bPassword='a''b'Connects: the ' is doubled
a'bPassword="a'b"Connects
a"bPassword="a""b"Connects: the " is doubled
a"bPassword='a"b'Connects

Why it matters. MySQL's IDENTIFIED BY RANDOM PASSWORD can produce ; and quotes, so this isn't rare. And because the exception is thrown where the string is read, in an app it's the first thing in the log. That line holds part of your password.

Why It Happens​

A connection string is a list of name=value pairs split by ;. It works the same way as a CSV line: a value holding the separator has to be quoted.

The Fix​

Quote the value. Use single quotes, and double any ' inside:

Connection string
Server=127.0.0.1;Port=3306;Database=inventory;User ID=quote_demo;Password='abc;def';SslMode=Required

Or let the driver write the string, which gets every case right:

connection-string.cs
// The builder quotes every value for you, whatever characters it holds.
var builder = new MySqlConnectionStringBuilder
{
Server = "127.0.0.1",
Port = 3306,
Database = "inventory",
UserID = "inventory_app",
Password = "a'b\"c;d",
SslMode = MySqlSslMode.Required,
};

Console.WriteLine(builder.ConnectionString);
Output
server=127.0.0.1;port=3306;database=inventory;user id=inventory_app;password="a'b""c;d";sslmode=Required

Or generate passwords without these characters. Hex from openssl rand -hex 24 has none, as How to Generate a Strong Random Password in the Terminal shows.

If that message reached your logs, treat the password as exposed, and change it.

After the Fix​

Terminal
dotnet run test-connection.cs
Output
Connected as quote_demo@% to MySQL 9.7.4
TLS: TLSv1.2

The test program printing Connected as quote_demo@% with TLS: TLSv1.2, with the password in single quotes in the connection string.

Common Mistakes​

MistakeWhat happensDo this instead
Escaping with a backslash: abc\;defThe ; still ends the value, and you get the same errorQuote the value
Quoting the value in the shell onlyThe shell removes those quotesQuote inside the string: "…Password='abc;def';…"
Assuming a password with no ; is safeSpaces at the ends are dropped tooGenerate hex passwords

Troubleshooting​

SymptomLikely causeFix
Access denied once it's quotedThe account's password has other characters than you thinkThe fix
It works locally, and fails in a containerThe tool that sets the variable handles quotes differentlyPrint the length of the value, not the value
Incorrect value in Connection String near 'Password'An opening quote with no closing quoteCheck the quotes match

Conclusion​

Option not supported with a strange parameter usually means a ; in a value. Quote it, or use MySqlConnectionStringBuilder, and check whether that message reached your logs.

Additional Resources​

Stay Updated

Subscribe to our newsletter for the latest tutorials, tech insights, and developer news.

By subscribing, you agree to our privacy policy. Unsubscribe at any time.