Bug #56859 | DatabaseExists() and CreateDatabase() use wrong database name | ||
---|---|---|---|
Submitted: | 19 Sep 2010 14:38 | Modified: | 26 Dec 2010 21:38 |
Reporter: | Tanguy Gilmont | Email Updates: | |
Status: | Closed | Impact on me: | |
Category: | Connector / NET | Severity: | S2 (Serious) |
Version: | 6.3.5 | OS: | Windows (Windows7) |
Assigned to: | Reggie Burnett | CPU Architecture: | Any |
Tags: | connection string, connector |
[19 Sep 2010 14:38]
Tanguy Gilmont
[19 Sep 2010 14:40]
Tanguy Gilmont
The same code used with SQLExpress works perfectly, for both methods.
[28 Sep 2010 18:15]
Tanguy Gilmont
Small VS2010 project that illustrates the problem
Attachment: DBExistsTest.zip (application/zip, text), 7.45 KiB.
[28 Sep 2010 18:18]
Tanguy Gilmont
Still no feedback, I've decided to add a small project example for VisualStudio 2010, and a database dump. The program does two tests, one with an existing MySQL database, one with a non-existing one. In both case you can see that DatabaseExists() returns false. The program tries to read the database records no matter what DatabaseExists() returned, and you can see that it can read normally in the first case, and of course it fails with the non-existing database. Example of output with the database provided in Database\mysql.sql: MySQL: DatabaseExists(DBExistsTest) = False User #1: Jack User #2: John MySQL: DatabaseExists(dummy) = False Could not read from database If you add a line Console.WriteLine(context.CreateDatabaseScript()); in the code, or if you actually try to create the database with context.CreateDatabase(); you will see that the wrong database name is put in the SQL command, hence the error. In the case of this little test application, the name I got was "dbexiststestModelStoreContainer", and should have been "DBExistsTest". If you do the same with an SQLExpress or SQL database, it works.
[4 Oct 2010 18:14]
Reggie Burnett
Fixed in 6.3.5
[6 Oct 2010 15:15]
Tony Bedford
An entry has been added to the 6.3.5 changelog: MySQL Connector/NET experienced two problems as follows: A call to System.Data.Objects.ObjectContext.DatabaseExists() returned false, even if the database existed. A call to System.Data.Objects.ObjectContext.CreateDatabase() created a database but with a name other than the one specified in the connection string. It then failed to use it when EDM objects were processed.
[25 Oct 2010 9:54]
Tanguy Gilmont
Actually, the problem is not fixed in version 6.3.5. Now the database part is omitted from the SQL script, which defaults to the MySQL database. 1) If you run the provided example, you will see that it crashes and the exception is clear enough: MySql.Data.MySqlClient.MySqlException was unhandled Message=Access denied for user 'test'@'localhost' to database 'mysql' 2) If you use the commented line that shows the database creation script, you will see the missing part: -- MySql script -- Created on 25/10/2010 11:50:56 CREATE TABLE `users`( `id` int NOT NULL AUTO_INCREMENT PRIMARY KEY, `name` varchar (80)); => no CREATE DATABASE, no USE <database name> commands.
[25 Oct 2010 9:57]
Tanguy Gilmont
(re-opened the case and updated version)
[25 Oct 2010 10:05]
Tanguy Gilmont
I tried a work-around by calling void ObjectContext.DbConnection.ChangeDatabase(string databaseName), but unfortunately this method is not implemented and throws an exception.
[11 Nov 2010 17:41]
Tanguy Gilmont
Could you identify the problem?
[17 Dec 2010 15:19]
Daniel Lidström
I'm having the same issue. Calling ObjectContext.DatabaseExists() results in MySql.Data.MySqlClient.MySqlException : Access denied for user 'root'@'localhost' (using password: NO). I'm using 6.3.5 with EntityFramework CTP 5.
[21 Dec 2010 14:14]
Tanguy Gilmont
Any progress on this? Will you fix the bug?
[24 Dec 2010 12:47]
Tanguy Gilmont
Should I create a new PR?
[25 Dec 2010 15:20]
Tanguy Gilmont
Apparently nobody would fix this bug, so closing the PR and creating a new one...
[26 Dec 2010 21:38]
Tanguy Gilmont
Just noticed that revision 932 referenced this bug as bug #56589 instead of #56859, in case you need this reference for another tool: "- fixed database methods in EF4 provider services to use the database name from the connection string (bug #56589)"
[29 Dec 2010 16:09]
Alex Vi
The current published Connector.NET version (6.3.5) still presents this bug. This makes Connector.NET unusable in most environments (because usually in hosting sites the application does not have access to 'mysql' database). msi package also has a dependency mismatch between two dll's. A new release should be published solving this errors (maybe 6.3.6?).