none
想请教如何slove Unrecognized database format 的问题。 RRS feed

  • 问题

  • 我的program出现了以下问题。 我尝试了solve 但是还是一直出现Unrecognized database format 'C:\Users\ME\Documents\Visual Studio 2010\Projects\Upload_and_Download\Upload_and_Download\My_Data\Asset.mdb'.

    想请各位大大帮忙看看.

    Imports System.Data.OleDb
    Imports System
    Imports System.Data

    Public Class Common

    Private Shared Function GetConnectionString() As String

     Return "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Form1.strFullDBPath + ";Jet OLEDB:Database Password=******;" 

        End Function

    Imports System.Data.OleDb

      Dim strCurrentPath As String
        Public strFullDBPath As String
        Dim cnn As OleDbConnection = New OleDbConnection()
        Dim cmd As New OleDb.OleDbCommand

        

      Me.CenterToScreen()
            strCurrentPath = CurDir() ' Replace(CurDir(), "\bin\Debug", "")
            strCurrentPath = Replace(CurDir, "\bin\Debug", "")
            strFullDBPath = strCurrentPath + "\My_Data" + "\Asset.mdb"

            cnn.ConnectionString = "Provider=Microsoft.Jet.Oledb.4.0; Data Source=" + strFullDBPath + ";Jet OLEDB:Database Password=******;"

            DataGridView1.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
            RefreshData()
        End Sub

        Private Sub RefreshData()

    问题会出现在这段code
            If Not cnn.State = ConnectionState.Open Then
                cnn.Open()
            End If


            Dim da As New OleDb.OleDbDataAdapter("SELECT ID,filename as [filename], download as [download], " & _
                                                 "delete as [delete]" & _
                                                 " FROM Asset ORDER BY ID", cnn)
            Dim dt As New DataTable
            da.Fill(dt)
            Me.DataGridView1.DataSource = dt
            Me.DataGridView1.Columns("ID").Visible = False

            cnn.Close()
        End Sub

    请指点。谢谢。感恩


    2020年10月9日 5:55

答案

  • Hi christing,

    该问题可能是由于生成连接字符串的向导选择的OleDb驱动程序不正确。

    Microsoft.Jet.OLEDB.4.0Oledb的连接方式是比较老的连接方式,而Access07以后的Oledb连接方式应为Microsoft.ACE.OLEDB.12.0,同时文件后缀名也从mdb变成accdb

    你可以尝试将连接更改为:Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\myFolder\*.accdb;……

    Best regards,

    Arya



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.



    • 已编辑 Arya Ding 2020年10月9日 7:37
    • 已标记为答案 christing 2020年10月12日 6:36
    2020年10月9日 7:22