Donate

Unknown database 'your_database' error In MySQL In app.config

There's a weird scenario when retrieving table names from a specific database, upon querying, using connection.Open() in C#, an error such as "Unknown database 'database_name'" shows in the exception object.

I was simply checking the database name using MySQL Browser and found out that the database name starts with a space. So, after thinking about it, I decided to modify the app.config and changed the value of the connection string by enclosing the name with single quotes to include the space character of the database name.

Not working app.config setting:
<add key="try" value="server=127.0.0.1;database=database_v1;Uid=james;pwd=pass123;"/> 
Working app.config setting with database name enclosed in single quotes:
<add key="try" value="server=127.0.0.1;database=' database_v1';Uid=james;pwd=pass123;"/> 
Note: This fix is applied towards database names that starts/ends with space.
Cheers! That was a quick fix! :D

Greg

Comments

Donate

Popular Posts From This Blog

WPF CRUD Application Using DataGrid, MVVM Pattern, Entity Framework, And C#.NET

How To Insert Or Add Emojis In Microsoft Teams Status Message

Bootstrap Modal In ASP.NET MVC With CRUD Operations