Microsoft KB Archive/294177

= BUG: SQLConfigDataSource Returns TRUE Even Without Registry Permissions =

Article ID: 294177

Article Last Modified on 5/10/2003

-

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.



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:  Use Regedit32.exe to disable read and write access to the following key:

HKEY_CURRENT_USER\Software\ODBC\ODBC.INI

  Compile and run the following code:
 * 1) include 
 * 2) include 
 * 3) include 
 * 4) include 

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, &quot;SQL Server&quot;,&quot;DSN=YourDSNName\0Server=YourServerName\0\0&quot;)) {    MessageBox(NULL,&quot;SQLConfigDataSource succeeded&quot;,        &quot;SQLConfigDataSource&quot;,MB_OK); }   else {    MessageBox(NULL,&quot;SQLConfigDataSource failed&quot;,        &quot;SQLConfigDataSource&quot;,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. 

Keywords: kbbug kbnofix KB294177

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.