none
mdb problem soleve me RRS feed

Answers

  • Greetings surendra,

    Might I suggest elaborating on exactly what kind of issue you are experiencing and include relevant code to reproduce the issue along with version of Windows (is it 32 or 64bit OS) and version of Visual Studio used. In the mean time here is a short example of opening a local MDB using OleDb which may not even be close to your problem.

    ''' <summary>
    ''' Open a MDB file in the same folder as the app executable
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub DemoOpenMsAccess()
        Dim FileName As String = IO.Path.Combine(Application.StartupPath, "MyDatabaseName.mdb")
    
        If IO.File.Exists(FileName) Then
            Dim cb As New OleDbConnectionStringBuilder With _
            { _
                .Provider = "Microsoft.Jet.OLEDB.4.0", _
                .DataSource = FileName _
            }
    
            Try
                Using cn As New OleDbConnection(ConnectionString)
                    cn.Open()
                    ' Create objects to work your data i.e.
                    Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM SomeTable", cn)
                    Dim dt As New DataTable With {.TableName = "MyTable"}
                    dt.Load(cmd.ExecuteReader)
                End Using
            Catch oex As OleDb.OleDbException
                If oex.Message.Contains("exclusively locked") Then
                    MessageBox.Show("You have the Customer table open")
                    Exit Sub
                Else
                    MessageBox.Show(String.Format("Failed to obtain data{0}{1}", Environment.NewLine, oex.Message))
                    Exit Sub
                End If
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try
        End If
    End Sub
    
    
    

     


    KSG
    Friday, November 25, 2011 4:24 PM
  • Hi surendra,

    Connection failure may because of the connection string has something wrong, you can get the correct connection string as below:

    1. Click 'Connection to Database' linkbutton in your server explorer;

    2. Click 'Change' button to select Access provider;

    3. Fill in your login information such as username and password and select which database you want to connect;

    4. Click OK button.

    Now, you have connected to your access database, at the properties window, you can get your correct connection string, use it in your program, then you can connect to your database.

    Best Regards 


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us
    Monday, November 28, 2011 2:31 AM
    Moderator

All replies

  • Greetings surendra,

    Might I suggest elaborating on exactly what kind of issue you are experiencing and include relevant code to reproduce the issue along with version of Windows (is it 32 or 64bit OS) and version of Visual Studio used. In the mean time here is a short example of opening a local MDB using OleDb which may not even be close to your problem.

    ''' <summary>
    ''' Open a MDB file in the same folder as the app executable
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub DemoOpenMsAccess()
        Dim FileName As String = IO.Path.Combine(Application.StartupPath, "MyDatabaseName.mdb")
    
        If IO.File.Exists(FileName) Then
            Dim cb As New OleDbConnectionStringBuilder With _
            { _
                .Provider = "Microsoft.Jet.OLEDB.4.0", _
                .DataSource = FileName _
            }
    
            Try
                Using cn As New OleDbConnection(ConnectionString)
                    cn.Open()
                    ' Create objects to work your data i.e.
                    Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM SomeTable", cn)
                    Dim dt As New DataTable With {.TableName = "MyTable"}
                    dt.Load(cmd.ExecuteReader)
                End Using
            Catch oex As OleDb.OleDbException
                If oex.Message.Contains("exclusively locked") Then
                    MessageBox.Show("You have the Customer table open")
                    Exit Sub
                Else
                    MessageBox.Show(String.Format("Failed to obtain data{0}{1}", Environment.NewLine, oex.Message))
                    Exit Sub
                End If
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try
        End If
    End Sub
    
    
    

     


    KSG
    Friday, November 25, 2011 4:24 PM
  • Hi surendra,

    Connection failure may because of the connection string has something wrong, you can get the correct connection string as below:

    1. Click 'Connection to Database' linkbutton in your server explorer;

    2. Click 'Change' button to select Access provider;

    3. Fill in your login information such as username and password and select which database you want to connect;

    4. Click OK button.

    Now, you have connected to your access database, at the properties window, you can get your correct connection string, use it in your program, then you can connect to your database.

    Best Regards 


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us
    Monday, November 28, 2011 2:31 AM
    Moderator
  • Hi surendra,

    Have you fixed your issue? I look forward to hearing from you. If you have any problems, please feel free to let me know.

    Best Regards,


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us
    Thursday, December 1, 2011 3:04 AM
    Moderator
  • Hi surendra,

    I marked Kevin's and my reply as answers, if you feel the solutions are not suitable, please unmark them. Any problems about this can be posted here, we'll do our best to help you.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us
    Sunday, December 4, 2011 3:36 AM
    Moderator