Using ADOX to creata a table on SQL Server

Using ADOX to creata a table on SQL Server

Post by Brian Youn » Thu, 31 Jan 2002 01:56:00



I'm trying to add a new table to a SQL Server database using the following
procedure. On the line where I append the table to the collection, I get the
following error: "Runtime Error '-2147024809(80070057);' The parameter is
incorrect."

Is it possible to create a table in this way? Does anyone know what the
problem is? Thanks for your help.

Public Sub CreateSQLTable(DatabaseName As String, ServerName As String,
UserID As String, Password As String, TableName As String)

 ' This procedure creates a new table in a database
    Dim oConn As ADODB.Connection
    Dim oCatalog As New ADOX.Catalog
    Dim oTable As New ADOX.Table
    Dim sData As String

  'Create a new ADO connection and set it equal to a file on the
  'sql server
    Set oConn = New ADODB.Connection
    oConn.Open "Provider=SQLOLEDB;Data Source=" & ServerName & ";User ID=" &
UserID & ";Password=" & Password & ";"

    'set the database and table and add assign the new table a name
    oCatalog.ActiveConnection = oConn
    Set oTable.ParentCatalog = oCatalog

    oTable.Name = TableName

    'append the table to the database
    oCatalog.Tables.Append oTable ' ERROR HAPPENS HERE

    'clean up
    oCatalog.ActiveConnection = Nothing
    Set oCatalog = Nothing
    Set oTable = Nothing
    Set oConn = Nothing
End Sub

 
 
 

Using ADOX to creata a table on SQL Server

Post by Val Mazu » Thu, 31 Jan 2002 02:56:59


Hi,

I am not sure, but as I know you cannot create table on
SQL Server using ADOX. Adding tables works with Jet. You
can use SQL DMO to create tables for SQL Server

Val

Quote:>-----Original Message-----
>I'm trying to add a new table to a SQL Server database
using the following
>procedure. On the line where I append the table to the

collection, I get the
Quote:>following error: "Runtime Error '-2147024809(80070057);'
The parameter is
>incorrect."

>Is it possible to create a table in this way? Does anyone
know what the
>problem is? Thanks for your help.

>Public Sub CreateSQLTable(DatabaseName As String,

ServerName As String,
Quote:>UserID As String, Password As String, TableName As String)

> ' This procedure creates a new table in a database
>    Dim oConn As ADODB.Connection
>    Dim oCatalog As New ADOX.Catalog
>    Dim oTable As New ADOX.Table
>    Dim sData As String

>  'Create a new ADO connection and set it equal to a file
on the
>  'sql server
>    Set oConn = New ADODB.Connection
>    oConn.Open "Provider=SQLOLEDB;Data Source=" &

ServerName & ";User ID=" &
Quote:>UserID & ";Password=" & Password & ";"

>    'set the database and table and add assign the new
table a name
>    oCatalog.ActiveConnection = oConn
>    Set oTable.ParentCatalog = oCatalog

>    oTable.Name = TableName

>    'append the table to the database
>    oCatalog.Tables.Append oTable ' ERROR HAPPENS HERE

>    'clean up
>    oCatalog.ActiveConnection = Nothing
>    Set oCatalog = Nothing
>    Set oTable = Nothing
>    Set oConn = Nothing
>End Sub

>.