Bug #65674 Connect/ODBC does not allow any communications without a selected database?
Submitted: 19 Jun 2012 16:33 Modified: 12 Jul 2012 3:47
Reporter: Maury Markowitz Email Updates:
Status: Not a Bug Impact on me:
None 
Category:Connector / ODBC Severity:S3 (Non-critical)
Version:5.1.11 OS:MacOS
Assigned to: Bogdan Degtyariov CPU Architecture:Any

[19 Jun 2012 16:33] Maury Markowitz
Description:
I'm not 100% sure I have correctly understood my own problem here, but...

If you leave out a database= or similar catalog selection entry in the DSN, Connection/ODBC connects fine to the server. However, any attempt to send a query fails with:

No database selected

Why is this a problem? Because the command I was trying to issue was to show the database list :-)

How to repeat:
Make a DSN to a local server, but do not select a database/catalog in the DSN. Connect and then issue any command.

Suggested fix:
Connecting to the 'mysql' database if no other is provided seems like one solution. Or the system could simply choose to not consider this to be an error condition for those case that are server-related (as opposed to data-related).
[20 Jun 2012 7:35] Bogdan Degtyariov
Maury,

I have no problem getting the database list using SHOW DATABASES command even if no default database is selected in my DSN.
Please check this output from odbcte32.exe (SELECT DATABASE(); returns NULL):
--------------------------------------------------------------------
Full Connect(Default)

	Env. Attr. SQL_ATTR_ODBC_VERSION set to SQL_OV_ODBC3

	Successfully connected to DSN 'test'.
SQLExecDirect:
In:	Statementhandle = 0x00E778F8, 
										StatementText = "select database();", Statementlength = 18
				Return:	SQL_SUCCESS=0

Get Data All:
"database()"
<Null>
1 row fetched from 1 column.

SQLExecDirect:
In:	Statementhandle = 0x00E778F8, 
										StatementText = "show databases", Statementlength = 14
				Return:	SQL_SUCCESS=0

Get Data All:
"Database"
"information_schema"
"mysql"
"mytest"
"performance_schema"
"test"
"test7"
"test9"
"test99"
"users"
"users3"
10 rows fetched from 1 column.

Did you try getting the database list in some other way?
[20 Jun 2012 15:01] Maury Markowitz
Bogdan: I followed your advice, and sure enough I can issue commands. The error I was seeing must be spurious. You can close this issue.