sqldata/sqlsncapi.cpp
// Define which SQL Server Native Client driver to use
Define which SQL Server Native Client driver to use
Define which SQL Server Native Client driver to use
void SqlSncApi::DefineDriver(std::string &driver, std::string &dll)
{
#if defined(WIN32) || defined(_WIN64)
	HKEY hKey;
	int rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\ODBC\\ODBCINST.INI", 0, KEY_READ | KEY_ENUMERATE_SUB_KEYS, &hKey);
	if(rc != ERROR_SUCCESS)
		return;
	char key[1024];
	DWORD i = 0;
	bool sql2000 = false;
	bool sql2005 = false;
	bool sql2008 = false;
	bool sql2012 = false;
	bool more = true;
	while(more)
	{
		int size = 1024;
		rc = RegEnumKeyEx(hKey, i, key, (LPDWORD)&size, NULL, NULL, NULL, NULL);
		if(rc != ERROR_SUCCESS)
		{
			more = false;
			break;
		}
		if(strcmp(key, "SQL Server") == 0)
			sql2000 = true;
		else
		if(strcmp(key, "SQL Native Client") == 0)
			sql2005 = true;
		else
		if(strcmp(key, "SQL Server Native Client 10.0") == 0)
			sql2008 = true;
		else
		if(strcmp(key, "SQL Server Native Client 11.0") == 0)
			sql2012 = true;
		i++;
	}
	RegCloseKey(hKey);
	if(sql2012)
	{
		driver = "Driver={SQL Server Native Client 11.0};";
		dll = "sqlncli11.dll";
	}
	else
	if(sql2008)
	{
		driver = "Driver={SQL Server Native Client 10.0};";
		dll = "sqlncli10.dll";
	}
	else
	if(sql2005)
	{
		driver = "Driver={SQL Native Client};";
		dll = "sqlncli.dll";
	}
	else
	if(sql2000)
	{
		driver = "Driver={SQL Server};";
		dll = "sqlsrv32.dll";
	}
#endif
}
void SqlSncApi :: DefineDriver ( std :: string & driver , std :: string & dll ) { #if defined ( WIN32 ) || defined ( _WIN64 ) HKEY hKey ; int rc = RegOpenKeyEx ( HKEY_LOCAL_MACHINE , " \\ \\ " , 0 , KEY_READ | KEY_ENUMERATE_SUB_KEYS , & hKey ) ; if ( rc != ERROR_SUCCESS ) return ; char key [ 1024 ] ; DWORD i = 0 ; bool sql2000 = false ; bool sql2005 = false ; bool sql2008 = false ; bool sql2012 = false ; bool more = true ; while ( more ) { int size = 1024 ; rc = RegEnumKeyEx ( hKey , i , key , ( LPDWORD ) & size , NULL , NULL , NULL , NULL ) ; if ( rc != ERROR_SUCCESS ) { more = false ; break ; } if ( strcmp ( key , " " ) == 0 ) sql2000 = true ; else if ( strcmp ( key , " " ) == 0 ) sql2005 = true ; else if ( strcmp ( key , " " ) == 0 ) sql2008 = true ; else if ( strcmp ( key , " " ) == 0 ) sql2012 = true ; i ++ ; } RegCloseKey ( hKey ) ; if ( sql2012 ) { driver = " " ; dll = " " ; } else if ( sql2008 ) { driver = " " ; dll = " " ; } else if ( sql2005 ) { driver = " " ; dll = " " ; } else if ( sql2000 ) { driver = " " ; dll = " " ; } #endif }
Define which SQL Server Native Client driver to use
Define which SQL Server Native Client driver to use
// Keys: SQL Server, SQL Server Native Client 10.0, SQL Server Native Client 11.0 // Enumerate through all keys // Size modified with each call to RegEnumKeyEx // Get next key // SQL Server 2000 driver // SQL Server 2005 Native client // SQL Server 2008 Native client // SQL Server 2012, 2014 and 2016 Native client // Return the highest available version (this driver is also used for 2014 and 2016)