BUG: Problems Reading and Writing Dynamic Properties of ADOX Column When You Use SQLOLEDB (288444)



The information in this article applies to:

  • ActiveX Data Objects (ADO) 2.5
  • ActiveX Data Objects (ADO) 2.6
  • ActiveX Data Objects (ADO) 2.7
  • Microsoft Visual Basic Professional Edition for Windows 6.0
  • Microsoft Visual Basic Enterprise Edition for Windows 6.0

This article was previously published under Q288444

SYMPTOMS

When you connect to SQL Server using the SQL Server OLE DB Provider, if you use ActiveX Data Objects Extensions for DDL and Security (ADOX), the ADOX Column object exposes six dynamic properties in its Properties collection: Autoincrement, Default, Fixed Length, Nullable, Primary Key, and Unique.

However, any attempt to read one of these properties on an existing Column in an existing Table generates the following error message:
Error 3251, "Object or provider is not capable..."
You may also encounter problems when you try to set these properties on a new Column unless you follow specific steps, which are described in the "More Information" section.

RESOLUTION

Because you cannot use ADOX to read these Column properties, you can use an ADO Connection or SQL Server Query Analyzer to run the equivalent T-SQL statements to query object properties; or you can use SQL Server Enterprise Manager to view the properties manually.

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

MORE INFORMATION

According to the Microsoft Data Access Components (MDAC) Readme file, the properties of existing Column objects in existing Tables are read-only. However, as a result of the bug discussed in this article, the above-mentioned properties cannot be read for existing Columns. You may also encounter problems when you try to set these properties on a new Column, unless you follow the specific steps, as described below.

Steps to Reproduce Behavior

How to Read Properties from Existing Column in an Existing Table

  1. Create a new Standard EXE project in Visual Basic. Form1 is created by default.
  2. From the Project menu, click References, and then click Microsoft ADO Ext. 2.x for DDL and Security and Microsoft ActiveX Data Objects 2.x Library.
  3. Paste the following code into a Form1, and adjust the SQL Server connection parameters as necessary.

    Note You must change User ID =<UID> and password =<strong password> to the correct values before you run this code. Make sure that <UID> has the appropriate permissions to perform this operation on the database.
      Dim cn As ADODB.Connection
      Dim cat As ADOX.Catalog
      Set cn = New ADODB.Connection
      With cn
        .Provider = "SQLOLEDB"
        .ConnectionString = "Data Source=(local);Initial Catalog=Northwind;User ID=<UID>;Password=<strong password>;"
        .Open
      End With
      Set cat = New ADOX.Catalog
      Set cat.ActiveConnection = cn
      Debug.Print cat.Tables("Customers").Columns("CustomerID").Properties("Primary Key").Value
    					
This sample attempts to determine whether the CustomerID column in the Customers table is part of the table's Primary Key and should return True. In fact, it causes the above-mentioned error message.

How to Set Properties on New Column in New Table

  1. Create a new Standard EXE project in Visual Basic. Form1 is created by default.
  2. From the Project menu, click References, and then click Microsoft ADO Ext. 2.x for DDL and Security and Microsoft ActiveX Data Objects 2.x Library.
  3. Paste the following code into a Form1, and adjust the SQL Server connection parameters as necessary.

    Note You must change User ID =<UID> and password =<strong password> to the correct values before you run this code. Make sure that <UID> has the appropriate permissions to perform this operation on the database.
      Dim cn As ADODB.Connection
      Dim cat As ADOX.Catalog
      Dim tbl As ADOX.Table
      Dim col As ADOX.Column
      Set cn = New ADODB.Connection
      With cn
        .Provider = "SQLOLEDB"
        .ConnectionString = "Data Source=(local);Initial Catalog=Northwind;User ID=<UID>;Password=<strong password>;"
        .Open
      End With
      Set cat = New ADOX.Catalog
      Set cat.ActiveConnection = cn
      Set tbl = New ADOX.Table
      tbl.Name = "ADOXTest"
      Set col = New ADOX.Column
      With col
        .Name = "testing"
        .Type = adInteger
      End With
      tbl.Columns.Append col
      tbl.ParentCatalog = cat     '<--- This is the important line!
      col.Properties("Default").Value = 1
      cat.Tables.Append tbl
    					
This sample specifies the Default value for new column. If you omit the line that specifies the table's ParentCatalog property, the last line of code generates the above-mentioned error message.

REFERENCES

For additional information, click the article numbers below to view the articles in the Microsoft Knowledge Base:

201826 PRB: Error 3265 When Accessing Properties Collection

271483 PRB: Limitations of Using ADOX with Providers Other than Microsoft Jet OLE DB Provider


Modification Type:MajorLast Reviewed:11/5/2003
Keywords:kbbug kbDatabase kbpending KB288444