{"id":1086,"date":"2009-10-30T10:56:38","date_gmt":"2009-10-30T08:56:38","guid":{"rendered":"https:\/\/alax.info\/blog\/?p=1086"},"modified":"2011-07-26T11:28:09","modified_gmt":"2011-07-26T09:28:09","slug":"microsoft-jet-oledb-4-0-progid-is-not-available-in-windows-7","status":"publish","type":"post","link":"https:\/\/alax.info\/blog\/1086","title":{"rendered":"Microsoft.Jet.OLEDB.4.0 ProgID is not available (Windows 7 but probably not only)"},"content":{"rendered":"<p>It was a sort of ridiculous problem: an attempt to instantiate a Microsoft.Jet.OLEDB.4.0 object failed with error. Still some applications are still running without problems connecting to Jet databases, how comes?<\/p>\n<p>There has been <a href=\"http:\/\/www.google.com\/search?q=Microsoft.Jet.OLEDB.4.0\">a number of posts on Internet<\/a>, but none of the top ones appeared to be relevant.<\/p>\n<p>The problem is reproduced extremely simple:<\/p>\n<pre style=\"background: #ffffff none repeat scroll 0% 0%; color: #000000; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;\"><span style=\"color: #800000; font-weight: bold;\">int<\/span> _tmain<span style=\"color: #808030;\">(<\/span><span style=\"color: #800000; font-weight: bold;\">int<\/span> argc<span style=\"color: #808030;\">,<\/span> _TCHAR<span style=\"color: #808030;\">*<\/span> argv<span style=\"color: #808030;\">[<\/span><span style=\"color: #808030;\">]<\/span><span style=\"color: #808030;\">)<\/span>\r\n<span style=\"color: #800080;\">{<\/span>\r\n    ATLVERIFY<span style=\"color: #808030;\">(<\/span>SUCCEEDED<span style=\"color: #808030;\">(<\/span>CoInitialize<span style=\"color: #808030;\">(<\/span><span style=\"color: #7d0045;\">NULL<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #800080;\">;<\/span>\r\n    <span style=\"color: #800080;\">{<\/span>\r\n        <span style=\"color: #696969;\">\/\/CoLoadLibrary(L\"C:\\\\Program Files (x86)\\\\Common Files\\\\System\\\\Ole DB\\\\oledb32.dll\", TRUE);<\/span>\r\n        CComPtr<span style=\"color: #800080;\">&lt;<\/span>IDBInitialize<span style=\"color: #800080;\">&gt;<\/span> pDbInitialize<span style=\"color: #800080;\">;<\/span>\r\n        <span style=\"color: #800000; font-weight: bold;\">const<\/span> HRESULT nResult <span style=\"color: #808030;\">=<\/span> pDbInitialize<span style=\"color: #808030;\">.<\/span>CoCreateInstance<span style=\"color: #808030;\">(<\/span><span style=\"color: #800000;\">L\"<\/span><span style=\"color: #0000e6;\">Microsoft.Jet.OLEDB.4.0<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #808030;\">,<\/span> <span style=\"color: #7d0045;\">NULL<\/span><span style=\"color: #808030;\">,<\/span> CLSCTX_INPROC_SERVER<span style=\"color: #808030;\">)<\/span><span style=\"color: #800080;\">;<\/span>\r\n        _tprintf<span style=\"color: #808030;\">(<\/span>_T<span style=\"color: #808030;\">(<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #0000e6;\">nResult 0x<\/span><span style=\"color: #0f69ff;\">%08x<\/span><span style=\"color: #0f69ff;\">\\n<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #808030;\">,<\/span> nResult<span style=\"color: #808030;\">)<\/span><span style=\"color: #800080;\">;<\/span>\r\n    <span style=\"color: #800080;\">}<\/span>\r\n    CoUninitialize<span style=\"color: #808030;\">(<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #800080;\">;<\/span>\r\n    <span style=\"color: #800000; font-weight: bold;\">return<\/span> <span style=\"color: #008c00;\">0<\/span><span style=\"color: #800080;\">;<\/span>\r\n<span style=\"color: #800080;\">}<\/span><\/pre>\n<p>Oops, the code gives error REGDB_E_CLASSNOTREG 0x80040154 &#8220;Class not registered&#8221;. It looked like system was unable to locate one of the internally used DLLs &#8211; oledb32.dll, and if we help by uncommenting the line commented in the code snippet above, the error changes to ERROR_MOD_NOT_FOUND 0x8007007e &#8220;The specified module could not be found&#8221;.<\/p>\n<p>The problem appears to be that one of the system components, which is involved, &#8220;Microsoft OLE DB Data Conversion Library&#8221; is registered with the system using a <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms724884%28VS.85%29.aspx\">REG_EXPAND_SZ<\/a> value, to be located using path &#8220;%CommonProgramFiles(x86)%\\System\\Ole DB\\oledb32.dll&#8221;. It is obvious that <strong>CommonProgramFiles(x86)<\/strong> is placeholder to be expanded, but does the expansion succeed?<\/p>\n<p><!--more--><\/p>\n<p>On my system there was no such environment string, so expansion failed. There however was <strong>CommonProgramFiles<\/strong>, and it pointed to correct location. So, this hot fix makes it work right:<\/p>\n<pre><span style=\"color: #603000;\">BOOL<\/span> UpdateEnvironmentVariables<span style=\"color: #808030;\">(<\/span><span style=\"color: #808030;\">)<\/span>\r\n<span style=\"color: #800080;\">{<\/span>\r\n    <span style=\"color: #603000;\">CString<\/span> sCommonProgramFilesX86<span style=\"color: #800080;\">;<\/span>\r\n    sCommonProgramFilesX86<span style=\"color: #808030;\">.<\/span><span style=\"color: #400000;\">GetEnvironmentVariable<\/span><span style=\"color: #808030;\">(<\/span>_T<span style=\"color: #808030;\">(<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #0000e6;\">CommonProgramFiles(x86)<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #800080;\">;<\/span>\r\n    <span style=\"color: #800000; font-weight: bold;\">if<\/span><span style=\"color: #808030;\">(<\/span>sCommonProgramFilesX86<span style=\"color: #808030;\">.<\/span>IsEmpty<span style=\"color: #808030;\">(<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #808030;\">)<\/span>\r\n    <span style=\"color: #800080;\">{<\/span>\r\n        <span style=\"color: #603000;\">CString<\/span> sCommonProgramFiles<span style=\"color: #800080;\">;<\/span>\r\n        sCommonProgramFiles<span style=\"color: #808030;\">.<\/span><span style=\"color: #400000;\">GetEnvironmentVariable<\/span><span style=\"color: #808030;\">(<\/span>_T<span style=\"color: #808030;\">(<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #0000e6;\">CommonProgramFiles<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #800080;\">;<\/span>\r\n        <span style=\"color: #800000; font-weight: bold;\">if<\/span><span style=\"color: #808030;\">(<\/span><span style=\"color: #808030;\">!<\/span>sCommonProgramFiles<span style=\"color: #808030;\">.<\/span>IsEmpty<span style=\"color: #808030;\">(<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #808030;\">)<\/span>\r\n        <span style=\"color: #800080;\">{<\/span>\r\n            ATLVERIFY<span style=\"color: #808030;\">(<\/span><span style=\"color: #400000;\">SetEnvironmentVariable<\/span><span style=\"color: #808030;\">(<\/span>_T<span style=\"color: #808030;\">(<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #0000e6;\">CommonProgramFiles(x86)<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #808030;\">,<\/span> sCommonProgramFiles<span style=\"color: #808030;\">)<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #800080;\">;<\/span>\r\n            <span style=\"color: #800000; font-weight: bold;\">return<\/span> TRUE<span style=\"color: #800080;\">;<\/span>\r\n        <span style=\"color: #800080;\">}<\/span>\r\n    <span style=\"color: #800080;\">}<\/span>\r\n    <span style=\"color: #800000; font-weight: bold;\">return<\/span> FALSE<span style=\"color: #800080;\">;<\/span>\r\n<span style=\"color: #800080;\">}<\/span>\r\n\r\n<span style=\"color: #800000; font-weight: bold;\">int<\/span> _tmain<span style=\"color: #808030;\">(<\/span><span style=\"color: #800000; font-weight: bold;\">int<\/span> argc<span style=\"color: #808030;\">,<\/span> _TCHAR<span style=\"color: #808030;\">*<\/span> argv<span style=\"color: #808030;\">[<\/span><span style=\"color: #808030;\">]<\/span><span style=\"color: #808030;\">)<\/span>\r\n<span style=\"color: #800080;\">{<\/span>\r\n    ATLVERIFY<span style=\"color: #808030;\">(<\/span>SUCCEEDED<span style=\"color: #808030;\">(<\/span>CoInitialize<span style=\"color: #808030;\">(<\/span><span style=\"color: #7d0045;\">NULL<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #800080;\">;<\/span>\r\n    <span style=\"color: #800080;\">{<\/span>\r\n        UpdateEnvironmentVariables<span style=\"color: #808030;\">(<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #800080;\">;<\/span>\r\n        CComPtr<span style=\"color: #800080;\">&lt;<\/span>IDBInitialize<span style=\"color: #800080;\">&gt;<\/span> pDbInitialize<span style=\"color: #800080;\">;<\/span>\r\n        <span style=\"color: #800000; font-weight: bold;\">const<\/span> HRESULT nResult <span style=\"color: #808030;\">=<\/span> pDbInitialize<span style=\"color: #808030;\">.<\/span>CoCreateInstance<span style=\"color: #808030;\">(<\/span><span style=\"color: #800000;\">L\"<\/span><span style=\"color: #0000e6;\">Microsoft.Jet.OLEDB.4.0<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #808030;\">,<\/span> <span style=\"color: #7d0045;\">NULL<\/span><span style=\"color: #808030;\">,<\/span> CLSCTX_INPROC_SERVER<span style=\"color: #808030;\">)<\/span><span style=\"color: #800080;\">;<\/span>\r\n        _tprintf<span style=\"color: #808030;\">(<\/span>_T<span style=\"color: #808030;\">(<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #0000e6;\">nResult 0x<\/span><span style=\"color: #0f69ff;\">%08x<\/span><span style=\"color: #0f69ff;\">\\n<\/span><span style=\"color: #800000;\">\"<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #808030;\">,<\/span> nResult<span style=\"color: #808030;\">)<\/span><span style=\"color: #800080;\">;<\/span>\r\n    <span style=\"color: #800080;\">}<\/span>\r\n    CoUninitialize<span style=\"color: #808030;\">(<\/span><span style=\"color: #808030;\">)<\/span><span style=\"color: #800080;\">;<\/span>\r\n    <span style=\"color: #800000; font-weight: bold;\">return<\/span> <span style=\"color: #008c00;\">0<\/span><span style=\"color: #800080;\">;<\/span>\r\n<span style=\"color: #800080;\">} <\/span><\/pre>\n<p>I am under impression that the problem is not specific to Windows 7. I remember similar symptoms on Windows XP system, but they were not critical and not investigated to solution. It rather seems that OLE DB component is registering itself using a reference to environment variable which is not present on a number of systems.<\/p>\n<div id=\"_mcePaste\" style=\"overflow: hidden; position: absolute; left: -10000px; top: 81px; width: 1px; height: 1px;\">\n<h3 class=\"r\"><a class=\"l\" onmousedown=\"return rwt(this,'','','res','1','AFQjCNEiQBNPN2MLUciPFN3dRVUU-1FyJA','&amp;sig2=GPxd_FHW5MyBRM2Op0Da1A','0CAoQFjAA')\" href=\"http:\/\/support.software602.com\/kb\/view.aspx?articleID=987\">Error code 80040154. <em>Class not registered<\/em><\/a><\/h3>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>It was a sort of ridiculous problem: an attempt to instantiate a Microsoft.Jet.OLEDB.4.0 object failed with error. Still some applications are still running without problems connecting to Jet databases, how comes? There has been a number of posts on Internet, but none of the top ones appeared to be relevant. The problem is reproduced extremely&hellip; <\/p>\n<p><a class=\"moretag\" href=\"https:\/\/alax.info\/blog\/1086\">Read the full article<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[63,95,280,59,279,281,123,278],"class_list":["post-1086","post","type-post","status-publish","format-standard","hentry","category-technology","tag-bug","tag-com","tag-environment","tag-microsoft","tag-ole","tag-oledb","tag-registry","tag-win7"],"_links":{"self":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/posts\/1086","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/comments?post=1086"}],"version-history":[{"count":0,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/posts\/1086\/revisions"}],"wp:attachment":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/media?parent=1086"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/categories?post=1086"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/tags?post=1086"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}