Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

BUG: SQLConfigDataSource Returns TRUE Even Without Registry Permissions


View products that this article applies to.

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 (http://support.microsoft.com/kb/256986/EN-US/ ) Description of the Microsoft Windows Registry

↑ Back to the top


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.

↑ Back to the top


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.

↑ Back to the top


Status

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

↑ Back to the top


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.

↑ Back to the top


Keywords: KB294177, kbnofix, kbbug

↑ Back to the top

Article Info
Article ID : 294177
Revision : 3
Created on : 5/10/2003
Published on : 5/10/2003
Exists online : False
Views : 320