[AccessD] ADO/X in Access Module to get MS-SQL scema info

Steve Conklin developer at ultradnt.com
Mon Mar 26 07:53:21 CDT 2007


Whether using ADO with OpenSchema, or ADOX catalog, I can get a list (rs) of
tables, but once I try to get PK, FK, or Index info, all I get is Error #
3251, "Object or Provider is not capable of performing requested operation."
Have tried both SQLOLEDB and MSDASQL as providers.  Used Ent. Mgr. to script
out as work-around, but have another situation where need to do thru Access.

Any ideas?  All code clipped from MSDN (latest attempt below)

Thanks in advance,
Steve

Code:
Sub Blah()
Dim con As New ADODB.Connection
Dim cat As New ADOX.Catalog

Dim rsTbl As ADODB.Recordset
Dim rsPK As ADODB.Recordset
Dim fld As ADODB.Field

Dim rCriteria As Variant
Dim rsSchema As ADODB.Recordset
Dim f As ADODB.Field

con.ConnectionString = _
 "Provider=SQLOLEDB;server=XX;database=XX;" & _
              "User ID=XX;password=xx"
'"provider=msdasql;DRIVER=SQL Server;"
con.Open

Debug.Print Err
Set rs = con.OpenSchema(adSchemaTables)

rs.MoveFirst
While Not rsTbl.EOF
    If Left(rsTbl("table_Name"), 3) <> "sys" Then
        If Left(rsTbl("table_Name"), 2) <> "dt" Then
        rCriteria = Array(Empty, Empty, Empty, Empty, rsTbl("table_Name"))
' ok until here:
        Set rsSchema = con.OpenSchema(adSchemaIndexes, rCriteria)

        Debug.Print "Recordcount: " & rsSchema.RecordCount

        While Not rsSchema.EOF
        Debug.Print "==================================================="

        For Each fld In rsSchema.Fields
           Debug.Print fld.Name
           Debug.Print fld.Value
           Debug.Print "------------------------------------------------"
        Next
        rsSchema.MoveNext
        Wend
        rsSchema.Close
        End If
    End If

rsTbl.MoveNext
Wend
con.Close
End Sub




More information about the AccessD mailing list