Bug #10334 sqldriverconnect fails with a system (global) dsn

Submitted: 3 May 2005 13:54 Modified: 26 Jul 2007 0:26
Reporter: eid0 Email Updates:
Status: Can't repeat Impact on me:
None 
Category:Connector / ODBC Severity:S1 (Critical)
Version:3.51.11 and 3.51.10 OS:Windows (win32)
Assigned to: CPU Architecture:Any

[3 May 2005 13:54] eid0
Description:
My program used myodbc for years. All went good with 3.51.06.
Now I upgraded myodbc and windoze and the myodbc didn't connect neither at localhost or remote hosts.
The dsn  i use is a global dsn. If I use it with access, access crash.
Don't know if it works with other kind of dns (user).
The log that I put in the myodbc driver doesn't appear in any place.

my code that doesn't work is:

if (SQLAllocHandle (SQL_HANDLE_ENV, NULL, &(serverenv->henv)) != SQL_SUCCESS)
return -1;

SQLSetEnvAttr (serverenv->henv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER) SQL_OV_ODBC3,SQL_IS_UINTEGER);

if (SQLAllocHandle (SQL_HANDLE_DBC, serverenv->henv, &(serverenv->hdbc)) != SQL_SUCCESS)
	    return -1;

status = SQLDriverConnect (serverenv->hdbc, 0, (UCHAR *) dataSource, SQL_NTS,(UCHAR *) &buf, sizeof (buf), &buflen, SQL_DRIVER_COMPLETE);

-------
The sqldriverconnect fails with a -1, dataSource is with value "DSN=nameofdsn". I have downgraded the myodbc to 3.51.6 and my code is working again, without any changes.

Greets

How to repeat:
create a global dsn

use this dsn with my code, or with access (access crash, my code returns -1 after sqldriverconnect

Suggested fix:
no idea
[15 May 2005 8:49] Vasily Kishkin
Sorry. But I could't repeat that bug. I created test program and it worked fine with DSN.
[15 May 2005 9:56] eid0
for Vasily Kishkin:
Hi, did you call SQLDriverConnect with (UCHAR *) dataSource = "DSN=nameofglobaldsn"  and nothing more in the string?
To me it always returns -1, downgrading myodbc sqldriverconnect works ok.

Thankyou
[16 May 2005 5:20] Vasily Kishkin
Probably there is a problem with SQL_DRIVER_COMPLETE in SQLDriverConnect(). I assigned the bug to developer.
[26 Jul 2007 0:26] Jim Winstead
As long as a valid window handle is provided as the second argument to SQLDriverConnect(), I have no problem using SQLDriverConnect(..., SQL_DRIVER_COMPLETE) on Microsoft Windows using 3.51.17. It uses GetForegroundWindow() to retrieve a window handle even though this is a console application. I've tested with both a user DSN and a system DSN.

Here's my test program:

#include <windows.h>
#undef UNICODE
#include <stdlib.h>
#include <sql.h>
#include <sqlext.h>
#include <stdio.h>

int main(int argc, char* argv[])
{
	SQLRETURN rc;
	SQLHENV henv;
	SQLHDBC hdbc;
	SQLCHAR in[500], out[500];
	SQLSMALLINT len;

	rc= SQLAllocEnv(&henv);
	if (!SQL_SUCCEEDED(rc))
		exit(1);

	rc= SQLAllocConnect(henv, &hdbc);
	if (!SQL_SUCCEEDED(rc)) {
		SQLRETURN lrc;
		SQLCHAR sqlstate[6], message[SQL_MAX_MESSAGE_LENGTH];
		SQLINTEGER native;
		SQLSMALLINT messagelen;

		lrc= SQLGetDiagRec(SQL_HANDLE_DBC, hdbc, 1, sqlstate, &native, message, sizeof(message), &messagelen);
		if (SQL_SUCCEEDED(lrc))
			fprintf(stderr, "state: %6s, message: %*s (%d)\n", sqlstate, messagelen, message, native);
		exit(1);
	}
	
	sprintf((char *)in, "%s", "DSN=sysneedinfo");
	rc= SQLDriverConnect(hdbc, GetForegroundWindow(), in, SQL_NTS, out, sizeof(out), &len, SQL_DRIVER_COMPLETE);

	if (!SQL_SUCCEEDED(rc)) {
		SQLRETURN lrc;
		SQLCHAR sqlstate[6], message[SQL_MAX_MESSAGE_LENGTH];
		SQLINTEGER native;
		SQLSMALLINT messagelen;

		lrc= SQLGetDiagRec(SQL_HANDLE_DBC, hdbc, 1, sqlstate, &native, message, sizeof(message), &messagelen);
		if (SQL_SUCCEEDED(lrc))
			fprintf(stderr, "state: %6s, message: %*s (%d)\n", sqlstate, messagelen, message, native);
		exit(1);
	}

	fprintf(stderr, "out: %*s\n", len, out);

	return 0;
}

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.041 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.