Solved Error -2146232576 in SHA256: Automation error in ms access

Ihk

Member
Local time
Today, 02:22
Joined
Apr 7, 2020
Messages
280
Hi,
May be some one specifically knows about this problem and solution.
I am using SHA256 hash function for password and some other things (app security). This function has been working fine, without any problems for the last 3 years, with mutli-User app (more than 35 user accounts). Hashed passwords are stored at registration and hashed are checked at login. (as I said not only limited to passwords).
At this stage changing the function is not possible because all users have to change passwords then.

Problem:
Today I had to do new windows installation, on my PC along with fresh copy of MS office 2021 (the same which I have been using before). After I did this update,
now I am getting this while I open the app (only at the pages where I have called this function).
1) I have other two PCs, where app works fine.
2) Problematic PC: has same window 11 as before, same ms office as before. fresh installed.
I also installed latest version of .NET Framework 4.8 Developer Pack
3) I tried to figure out line in the function (as in code),
then I got this
Error -2146232576 in SHA256: Automation error at line 0 , again indicating function itself has no problem.
4) I tried running this (regsvr32 msxml3.dll) and "DllRegisterServer in msxml3.dll succeeded".

I also checked
I checked this on the PC where my program works, then I compared with the PC where i have problem..
on both PC available references are tick marked.
1) Visual basic for applications
2) Micro... Access 16.0 Object Library
3) OLE Automation
4) Micro.... office 16.0 Access database engine object Library

I have no other libraries activated.

Few weeks back, this error happened (Error -21462325756 in SHA256: Automation error in Ms access) on one of the PC of a client for another app, because app was at its initial stage so I had to replace the function completely.

Did any one encountered such problem (because it is not general, rather it is PC specific. Few PCs give this error while mostly not.)
As I said, I got this problem after more three years, and it has been being used more than 50 different PCs at least. Function itself has no problem at all. Probably any component is missing in such PCs.
Many thanks.

------------------------------------------------------------------

Code:
Option Compare Database
Option Explicit

' This function uses SHA256 to hash the input string
Public Function MYFUNCTIONNAME(ByVal sInput As String) As String
    On Error GoTo ErrorHandler
    MYFUNCTIONNAME = SHA256(sInput)
    Exit Function

ErrorHandler:
    MsgBox "Error in MYFUNCTIONNAME: " & Err.Description
    MYFUNCTIONNAME = ""
End Function


Public Function SHA256(ByVal sInput As String, Optional ByVal bB64 As Boolean = False) As String
    On Error GoTo ErrorHandler
   
    ' Create objects for encoding and hashing
    Dim Encoder As Object
    Set Encoder = CreateObject("System.Text.UTF8Encoding")

    Dim Hasher As Object
    Set Hasher = CreateObject("System.Security.Cryptography.SHA256Managed")
   

    Dim TextToHash() As Byte
    TextToHash = Encoder.GetBytes_4(sInput)
   

    Dim Hash() As Byte
    Hash = Hasher.ComputeHash_2(TextToHash)
   
    ' Convert the hash to the desired format
    If bB64 = True Then
        SHA256 = ConvToBase64String(Hash)
    Else
        SHA256 = ConvToHexString(Hash)
    End If
   
    Exit Function

ErrorHandler:
    MsgBox "Error " & Err.Number & " in SHA256: " & Err.Description

    SHA256 = ""
End Function


Public Function ConvToBase64String(ByVal vIn As Variant) As Variant
    On Error GoTo ErrorHandler


    Dim oD As Object
    Set oD = CreateObject("MSXML2.DOMDocument")
   

    With oD
        .LoadXML "<root />"
        .DocumentElement.DataType = "bin.base64"
        .DocumentElement.nodeTypedValue = vIn
    End With
   
    ConvToBase64String = Replace(oD.DocumentElement.Text, vbLf, "")
   
    Exit Function

ErrorHandler:
    MsgBox "Error in ConvToBase64String: " & Err.Description
    ConvToBase64String = ""
End Function


Public Function ConvToHexString(ByVal vIn As Variant) As Variant
    On Error GoTo ErrorHandler

    ' Create a DOMDocument object
    Dim oD As Object
    Set oD = CreateObject("MSXML2.DOMDocument")
   
    ' Load the byte array as hexadecimal data
    With oD
        .LoadXML "<root />"
        .DocumentElement.DataType = "bin.Hex"
        .DocumentElement.nodeTypedValue = vIn
    End With
   
    ConvToHexString = Replace(oD.DocumentElement.Text, vbLf, "")
   
    Exit Function

ErrorHandler:
    MsgBox "Error in ConvToHexString: " & Err.Description
    ConvToHexString = ""
End Function
 
Last edited:
Did you change the bitness of the access install?
 
Did you change the bitness of the access install?
No change in bit, before and after pc has 64bit.
Accdb file works fine on my other two pcs, even on this pc as well before this fresh installation.
 
Something is EXTREMELY wrong here because -21,462,325,756 is an 11-digit decimal number, which is not a possible error code. A 32-bit (LONG) error code tops out at 10 digits the largest of which is 4,294,967,295 (as an unsigned number) and your number is clearly larger than this. Error codes are actually supposed to be signed negative numbers; the most negative number is 8000 0000 (hex), which is -2,147,483,648 (decimal).

This number that you reported, when converted to hexadecimal, takes too many bits: FFFF FFFB 00BE E604 - which isn't supposed to happen. That is, Windows error codes, even for 64-bit Windows, are NOT longer than 32 bits, but this appears to not take less than 35 bits. I'm not even sure how you got that number that you reported. Please double-check that you didn't add a digit somewhere. You have a very serious problem if that transcription is correct.

This is the structure of error/result codes under Windows:


You can browse around that area to see how error codes are structured.
 
  • Like
Reactions: Ihk
Something is EXTREMELY wrong here because -21,462,325,756 is an 11-digit decimal number, which is not a possible error code. A 32-bit (LONG) error code tops out at 10 digits the largest of which is 4,294,967,295 (as an unsigned number) and your number is clearly larger than this. Error codes are actually supposed to be signed negative numbers; the most negative number is 8000 0000 (hex), which is -2,147,483,648 (decimal).

This number that you reported, when converted to hexadecimal, takes too many bits: FFFF FFFB 00BE E604 - which isn't supposed to happen. That is, Windows error codes, even for 64-bit Windows, are NOT longer than 32 bits, but this appears to not take less than 35 bits. I'm not even sure how you got that number that you reported. Please double-check that you didn't add a digit somewhere. You have a very serious problem if that transcription is correct.

This is the structure of error/result codes under Windows:


You can browse around that area to see how error codes are structured.
You are right, Sorry my typo error.
Code error number is -2146232576 , I will correct in above.
 
just copied your code and ran it - works fine in 32bit access but get the error (-2,146,232,576) in 64bit access.

error occurs on this line
Set Encoder = CreateObject("System.Text.UTF8Encoding")

and will also occur on this line
Set Hasher = CreateObject("System.Security.Cryptography.SHA256Managed")

So looks like you need a different objects for 64bit
 
I never thought to test it. Also works for me in 2007 32bit.
 
No change in bit, before and after pc has 64bit.
Gasman was referring to the "bitness" of Office. Not the "bitness" of the PC and Windows. 64 bit office has been around for many years but until recently, the recommended install has been 32-bit unless you needed to support humongous spreadsheets. MS seems to have now changed the default install to 64-bit.
 
Thank you @CJ_London , @Pat Hartman,@Gasman @The_Doc_Man

The same Ms Access app, of which I have not changed this code since months.
Because of this error I transferred in USB ( merged front backend), and tested on my personal PCs

1) Main PC: (win 11 , 64bit and Office 2021 64bit)

Till yesterday app working was fine.
But after windows + Office Re-installation is the problem
On which have been working fine before this Re-Install

2) PC2: (win 10 , 6bit and Office 2019 64bit)
App works fine all the times.

3) PC3: (Win 10, 64bit but Office 2019 32bit)
App works fine all the times.

After I changed the error handling section of as below to check the line of code to find problem.
I got this error Error -2146232576 in SHA256: Automation error at line 0
1696260480746.png


On my client side, where more than 30 users use the app, it is working too. They also have different environment PCs 32 and 64bit on network, any user can use any pc with their network credentials.
As I mentioned above in 1st post, one of my other client also mentioned the same problem (1:5 PCs) which I am facing on my own PC now. I never could find the solution.

@CJ_London Hashing I can not change from environment to environment, because on network PC what if user changes the pc to loging, while he created account on different PC.

I can create sample db and upload here, but the problem is, it will work with most of you guys PC.


Code:
Public Function SHA256(ByVal sInput As String, Optional ByVal bB64 As Boolean = False) As String
    On Error GoTo ErrorHandler
   
    ' Create objects for encoding and hashing
    Dim Encoder As Object

    Set Encoder = CreateObject("System.Text.UTF8Encoding")
    If Err.Number <> 0 Then
        MsgBox "Error creating UTF8Encoding object"
        Exit Function
    End If

    Dim Hasher As Object

    Set Hasher = CreateObject("System.Security.Cryptography.SHA256Managed")
    If Err.Number <> 0 Then
        MsgBox "Error creating SHA256Managed object"
        Exit Function
    End If
   
    ' Convert the input string to bytes
    Dim TextToHash() As Byte
    TextToHash = Encoder.GetBytes_4(sInput)
   
    ' Compute the hash
    Dim Hash() As Byte
    Hash = Hasher.ComputeHash_2(TextToHash)
   
    ' Convert the hash to the desired format
    If bB64 = True Then
        SHA256 = ConvToBase64String(Hash)
    Else
        SHA256 = ConvToHexString(Hash)
    End If
   
    Exit Function

ErrorHandler:
    MsgBox "Error " & Err.Number & " in SHA256: " & Err.Description & " at line " & Erl

    SHA256 = ""
End Function

@MajP , @arnelgp
 
Last edited:
Suggest check access version/updates, (I use 365 version for my 64bit) you may need to go back to a previous update
 
OK, translating -2146232576 to hex gives back the error 0x80131700, which I then used in a search. I find that it occurs for various reasons but most probably caused by incompatibility with the version of .NET that you have installed on the machines, which in turn MAY depend on recent updates. So far, every case I have looked up suggested that it was .NET related. I don't know if that will help or not, but it seems to be a place to start.




 
So try a windows update and see if you get a .Net Update?
 
@Gasman @The_Doc_Man
Today after my system update, I started getting this error.
I knew that this error is probably for .Netframework, which is used in code.
Therefore I downloaded the latest one 4.8 developers one.
Did windows update.
Still have the same problem.
Not yet tried, but probably should older version of .net.
Lets see what happens, before change everything in code part. This is for sure problem is in pc environment, like .net or com.
 
In general the .Net FX should be fully compatible and available on both 32bit and 64bit. - Unfortunately, I have not clue what is going wrong with your code.

At this stage changing the function is not possible because all users have to change passwords then.
Well, if you just change the internal implementation of how the SHA265 hash is generated, it shouldn't make any difference for the computed hashes.

I recently posted a text and sample module on how to compute hashes using the Windows API.
This does not support SHA265 out-of-the-box. However, it should be fairly simple to switch to a different crypto provider, which also supports SHA256.
 
Thank you all of you for your help. Problem solved.
1) Uninstalled netframework 4.8 and installed 3.5 sp1. Restarted pc.
2) Launched my app, Now I got different error (no more previous automation error mentioned in post title)
I got this error (error 91 In SHA256: Object variable or with block variable not set at line 0)

then I changed my code a miner , error handling specifically around "CreateObject", and added Check to ensure Hashed object is successfully created.

Afterward no error, app started working fine. Now even I uninstalled 3.5 framework, and wanted to try latest one 4.8. Even without any framework it is working.
Probably some features of the .NET Framework are still be active even if I have uninstalled the framework (apparently).
Could not 100% understood this compatibility at deeper level. But app is working.



Code:
Public Function SHA256(ByVal sInput As String, Optional ByVal bB64 As Boolean = False) As String
    On Error GoTo ErrorHandler
   
    ' Create objects for encoding and hashing
    Dim Encoder As Object

    Set Encoder = CreateObject("System.Text.UTF8Encoding")
    If Err.Number <> 0 Then
        MsgBox "Error creating UTF8Encoding object"
        Exit Function
    End If

    Dim Hasher As Object
    Set Hasher = CreateObject("System.Security.Cryptography.SHA256Managed")
   
    If Hasher Is Nothing Then
        MsgBox "Error creating SHA256Managed object"
        Exit Function
    End If
   
    ' into bytes
    Dim TextToHash() As Byte
    TextToHash = Encoder.GetBytes_4(sInput)
   
    ' hash
    Dim Hash() As Byte
    Hash = Hasher.ComputeHash_2(TextToHash)
   
    ' format
    If bB64 = True Then
        SHA256 = ConvToBase64String(Hash)
    Else
        SHA256 = ConvToHexString(Hash)
    End If
   
    Exit Function

ErrorHandler:
    MsgBox "Error " & Err.Number & " in SHA256: " & Err.Description & " at line " & Erl
    SHA256 = ""
End Function
 
Start comparing net versions then?
Also if you knew it was a .net issue, it would have been really useful to mention that at the beginning? :(
 
@Gasman @The_Doc_Man
Today after my system update, I started getting this error.
I knew that this error is probably for .Netframework, which is used in code.
Therefore I downloaded the latest one 4.8 developers one.
Did windows update.
Still have the same problem.
Not yet tried, but probably should older version of .net.
Lets see what happens, before change everything in code part. This is for sure problem is in pc environment, like .net or com.

Yep, if it starts misbehaving after an update, you know something got changed in an underlying program element. And I'll add that the digits '13' in the code tell you the facility, which - if it is related to .NET - would be specific. Which problem explains why all the reports I found were related to the version of .NET on the given system.
 
Start comparing net versions then?
Also if you knew it was a .net issue, it would have been really useful to mention that at the beginning? :(
First of all thank you for you for help.
I was not 100% sure about .netframework, but in doubt that this is the issue. But on the other hand I was thinking while I have latest version 4.8 .netframework, then probably it is not the issue.
Initially I just mentioned installation of .netframework in this sense, that experts will get this.
 
Last edited:
@Gasman - I don't fault lhk at all for not initially knowing it was .NET related, because the error code transcription problem confused things. Once I pointed to the code discrepancy, the error code was corrected, and that enabled tracking it to an issue in .NET versions.

Sometimes detective work takes a moment or two. But lhk has a solution and was able to fix everything around the error. And that solution was available in 5 1/2 hours approximately. Same-day service. So that is a win for the forum.
 
As your code specifies ... " in line " & erl ...then it would say 0 as you aren't using line numbering (so erl=0)

Hope that makes sense
 

Users who are viewing this thread

Back
Top Bottom