Article ID: 198535
Article Last Modified on 3/14/2005
"Microsoft ADO Ext. 2.x for DDL and Security"
"Microsoft ActiveX Data Objects 2.x Library"
Dim cnn As ADODB.Connection
Dim cat As ADOX.Catalog
Dim tbl As ADOX.Table
Dim fky As ADOX.Key
Dim idx As ADOX.Index
Set cnn = CreateObject("ADODB.Connection")
Set cat = CreateObject("ADOX.Catalog")
Set fky = CreateObject("ADOX.Key")
Set tbl = CreateObject("ADOX.Table")
Set idx = CreateObject("ADOX.Index")
'Uncomment the following line to see "Not Implemented" or "No such interface supported" error.
'cat.Create "Provider=SQLOLEDB;Data Source=your_server;"
With cnn
.ConnectionString = "PROVIDER=sqloledb;" & _
"DATA SOURCE=your_server;" & _
"USER ID=<user name>;PASSWORD=<strong password>;" & _
"INITIAL CATALOG=pubs"
.Open
End With
Set cat.ActiveConnection = cnn
'Create a Parent table.
With tbl
.Name = "tbl_1"
.Columns.Append "Col_1", adInteger
.Columns.Append "Col_2", adVarChar, 10
End With
'Create a Primary Key on the Parent table.
With idx
.Clustered = False
.Columns.Append "Col_1"
.Name = "tbl_1_pk"
.PrimaryKey = True
End With
'Add the Index to the table's Indexes collection.
tbl.Indexes.Append idx
'Actually create the table and index on the server.
cat.Tables.Append tbl
Set tbl = Nothing
Set tbl = CreateObject("ADOX.Table")
'Create a Child table.
With tbl
.Name = "tbl_2"
.Columns.Append "Col_1", adInteger
.Columns.Append "Col_2", adVarChar, 10
End With
'Create the Foreign Key.
With fky
.Columns.Append "Col_1"
.Name = "fkey"
.RelatedTable = "tbl_1"
.Columns("Col_1").RelatedColumn = "Col_1"
.Type = adKeyForeign
End With
'Add the Foreign key to the child table's Keys Collection.
tbl.Keys.Append fky
'Actually create the child table and Foreign Key on the Server.
'This is the line that will generate the error :
'"No such interface support"
'Comment the previous line of code and the table will be
'successfully created on the server, minus the Foreign Key.
cat.Tables.Append tbl
'To workaround the problem, you can add the Foreign Key via a SQL statement instead:
'cat.ActiveConnection.Execute "ALTER TABLE tbl_2 ADD CONSTRAINT Col_1 " & _
"FOREIGN KEY(Col_1) REFERENCES tbl_1(Col_1)"
198534 INFO: ADOX Readme File Included with ADO 2.1 Components
Keywords: kberrmsg kbdatabase kbprb KB198535