How to find out that the database needs a password?

Mansour_Dalir 1,716 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
Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,869 questions
Access
Access
A family of Microsoft relational database management systems designed for ease of use.
336 questions
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,657 questions
{count} votes

Accepted answer
  1. Jiachen Li-MSFT 28,781 Reputation points Microsoft Vendor
    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.


0 additional answers

Sort by: Most helpful