我有一箇舊的VB6應用程序,我終於更新到.NET,但我碰到了一個絆腳石:它提供的一件事是提供當前連接到數據庫的列表,使用ADODB和this GUID specified by Microsoft發佈的提供程序特定架構行集。這裏是工作ADODB代碼使用ADO.NET/OLEDB獲取Jet用戶名冊
Set RS = CN.OpenSchema(adSchemaProviderSpecific, , "{947bb102-5d43-11d1-bdbf-00c04fb92675}")
現在我知道我仍然可以使用這個ADODB方法,如果我要加入到最新的COM ActiveX數據對象庫的引用,但我真的想避免這種情況,如果在所有可能的,並找到一種使用OLEDB做到這一點。
我已經創建了下面的函數,並嘗試了GetOleDbSchemaTable的各種組合。GetSchema - 既有限制也有沒有限制,並且GUID作爲字符串傳遞,但它總是錯誤或返回空表。
'Get a list of users connected to the core database
Public Function GetUserRoster() As DataTable
Dim connString As String = GetConnString(coreDB)
If String.IsNullOrEmpty(connString) Then Return Nothing
Using conn As New OleDbConnection(connString)
Try
conn.Open()
Dim oGUID As New Guid("{947bb102-5d43-11d1-bdbf-00c04fb92675}")
Dim restrictions() As String = {Nothing, Nothing, Nothing, "Table"}
Dim schemaTable As DataTable = conn.GetOleDbSchemaTable(oGUID, restrictions)
Return schemaTable
Catch ex As Exception
logger.Error("Failed to evaluate the database user roster. {0}{1}", vbCrLf, ex.ToString)
End Try
End Using
Return Nothing
End Function
所以,這是甚至可能或者我沒有別的選擇,只能使用舊的COM ADODB功能?
這是類似的東西嗎? http://msdn.microsoft.com/en-us/library/kcax58fh.aspx –
@YuriyGalanter是的,在過去的兩天裏我已經讀過那篇文章 - 還有其他幾十篇文章,而且我還沒有聰明。不幸的是,我發現的所有例子都只顯示瞭如何檢索表格信息......我已經知道該怎麼做。 – Antagony
我看起來有點太明顯,在.NET中沒有直接關聯,你可能不得不通過COM interop使用ADODB –