BUG: SQLConfigDataSource Returns TRUE Even Without Registry Permissions (294177)



The information in this article applies to:

  • Microsoft Data Access Components 2.1
  • Microsoft Data Access Components 2.5
  • Microsoft Data Access Components 2.6
  • Microsoft Data Access Components 2.7
  • Microsoft Open Database Connectivity 3.5

This article was previously published under Q294177
IMPORTANT: This article contains information about modifying the registry. Before you modify the registry, make sure to back it up and make sure that you understand how to restore the registry if a problem occurs. For information about how to back up, restore, and edit the registry, click the following article number to view the article in the Microsoft Knowledge Base:

256986 Description of the Microsoft Windows Registry

SYMPTOMS

When you use the ODBC API function SQLConfigDataSource to add, modify, or delete a data source (DSN), SQLConfigDataSource may return TRUE even though you don't have the appropriate permissions and the operation was not completed.

CAUSE

SQLConfigDataSource attempts to update the registry key where this information is stored.

For a user DSN:

HKEY_CURRENT_USER\Software\ODBC\ODBC.INI

For a system DSN:

HKEY_LOCAL_MACHINE\Software\ODBC\ODBC.INI

If you do not have read/write access to the registry, the DSN information cannot be updated but SQLConfigDataSource incorrectly returns TRUE.

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

MORE INFORMATION

Steps to Reproduce Behavior

WARNING: If you use Registry Editor incorrectly, you may cause serious problems that may require you to reinstall your operating system. Microsoft cannot guarantee that you can solve problems that result from using Registry Editor incorrectly. Use Registry Editor at your own risk.
To reproduce the problem, follow these steps:
  1. Use Regedit32.exe to disable read and write access to the following key:

    HKEY_CURRENT_USER\Software\ODBC\ODBC.INI

  2. Compile and run the following code:
    #include <windows.h>
    #include <sql.h>
    #include <sqlext.h>
    #include <odbcinst.h>
    
    int WINAPI WinMain(HINSTANCE hinst,HINSTANCE pinst,LPSTR szCmd,int nShow)
    {
            // The following code attempts to add a user DSN.
    	if (SQLConfigDataSource(NULL,ODBC_ADD_DSN,
    	 "SQL Server","DSN=YourDSNName\0Server=YourServerName\0\0"))
    	{
    	 MessageBox(NULL,"SQLConfigDataSource succeeded",
    		"SQLConfigDataSource",MB_OK);
    	}
    	else
    	{
    	 MessageBox(NULL,"SQLConfigDataSource failed",
    		"SQLConfigDataSource",MB_OK);
    	}
    	return 0;
    }
    					
    Note that SQLConfigDataSource returns TRUE but the new entry does not exist. If you run this code with the appropriate permissions, the new entry will exist.

Modification Type:MajorLast Reviewed:5/10/2003
Keywords:kbbug kbnofix KB294177