How to find out that the database needs a password?

Mansour_Dalir 1,996 Reputation points
2023-07-12T19:24:46.8533333+00:00

hi , thank

     'Need Check MyDataBase.accdb
      Dim sttPassword as string
     Dim oleConString As String=""
      If bitNeedPassword then
     sttPassword =InputBox("Please Enter Your Password")
      oleConString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=DbPath;Jet OLEDB:Database Password=sttPassword ;"
      else 'Not Needed 
      oleConString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=DbPath"
    Endif
Developer technologies | Windows Forms
Developer technologies | VB
Microsoft 365 and Office | Access | For business | Windows

1 answer

Sort by: Most helpful
  1. Jiachen Li-MSFT 34,166 Reputation points Microsoft External Staff
    2023-07-13T01:56:30.35+00:00

    Hi @Mansour_Dalir ,

    You can refer to the following code,

            Dim sttPassword As String
            Dim connectionString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=DbPath;"
            Using connection As New OleDbConnection(connectionString)
                Try
                    connection.Open()
                Catch ex As OleDbException
                    If ex.ErrorCode = "The error code you get after testing" Then
                        sttPassword = TextBoxPwd.Text
    
                        connectionString += "Jet OLEDB:Database Password=" + sttPassword + ";"
    
                        connection.ConnectionString = connectionString
                        connection.Open()
                    Else
                        MessageBox.Show(ex.Message)
                    End If
                Finally
                    connection.Close()
                End Try
    

    Best Regards.

    Jiachen Li


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.