VBAとVB.NETで作業する場合、私は説明できない問題があります。私はVBAで必要なアクセスデータを使ってプロジェクトを開始します。VBAとVB.NETでADOオブジェクトが異なる
Option Explicit
Private uConnect As ADODB.Connection
Private uCommand As ADODB.Command
Private uRecordset As ADODB.Recordset
Public Sub openConnection()
On Error GoTo ERRHANDLE:
Dim sConnection As String
sConnection = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source=" & ThisWorkbook.Path & "\" & "database.xlsx;" & _
"Extended Properties=Excel 12.0;"
'declare
Set uConnect = New ADODB.Connection 'give memory
uConnect.ConnectionString = sConnection
uConnect.Open
ERRHANDLE:
If Err.Number <> 0 Then
MsgBox Err.Description, vbCritical, "Error"
End If
End Sub
私が同じ状況にVB.NETで別のプロジェクトを開始する場合:私は、すべてがこの例のコードでうまく動作(アクティブ・データが6.1オブジェクト)ADOを使用していました。私のシステムは、10 64ビットに勝つ
Public Class Input
Private Const connstring As String = "Provider=Microsoft.ACE.OLEDB.12.0;" &
"Data Source=" & sSource & ";" &
"Extended Properties=Excel 12.0;"
Private Sub btnGetData_Click(sender As Object, e As EventArgs) Handles btnGetData.Click
Dim cn As New Connection
Dim da As New Recordset
Dim sSQL As String
Try
My.Computer.Audio.PlaySystemSound(SystemSounds.Exclamation)
da = New Recordset
cn = New Connection
cn.ConnectionString = connstring
cn.Open()
MessageBox.Show(cn.State.ToString)
cn.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Database Input Error")
End Try
End Sub
End Class
:まず私は、COM ADOへの参照(アクティブデータは6.1オブジェクト)またはアセンブリ参照ADODBを使用して、両方のエラー「プロバイダが見つかりません」では動作しない、コードを試してみてください。オフィス64ビット。
インターネットで、Access Database Engineをインストールするという解決策が見つかりました。問題は、2番目のケースを解決します。しかし、なぜVBAとVB.NETにこのような違いがあるのですか。なぜVBAはエンジンをインストールする必要がないのですか?
を変換するというハードな方法を学びました。 x86'では、GACのリファレンスとプロジェクト参照のリファレンスを取得していないことを確認し、そのDLLの 'CopyLocal = 'プロパティを' True'に変更します。 – MethodMan
COM ADODBライブラリを使用する理由'System.Data.Odbc'のような管理されたプロバイダを使用するのではなく、 – Comintern
@MethodMan:私は、Accessデータベースエンジン[link](http://www.connectionstrings.com/the-microsoft-ace-oledb-12-0-provider-is-news)をインストールするまで、x86とx64の両方が動作しません。 –