By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,234 Members | 1,869 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,234 IT Pros & Developers. It's quick & easy.

Error Creating Table in ADOX

P: n/a
I am getting an error that "object no longer valid" at the point indicated
in the code below - I am trying to build a table in an Access 2000 database
using ADOX. Any thoughts on what might cause this?

==================== code =================
Sub CreateADOUnitsTable(ByVal sTablename As String)

Dim oDB As ADOX.Catalog

Dim oUnits As ADOX.Table

oUnits = New ADOX.Table

oDB = New ADOX.Catalog

oDB.ActiveConnection = myConn

With oUnits

..Name = sTablename

..Columns.Append("UnitName", ADOX.DataTypeEnum.adVarWChar, 20)

..Columns.Append("Class", ADOX.DataTypeEnum.adVarWChar, 5)

..Columns.Append("Comments", ADOX.DataTypeEnum.adVarWChar, 35)

End With

oDB.Tables.Append(oUnits) '<=== Error occurs here

oUnits = Nothing

oDB = Nothing

End Sub
Nov 21 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Wayne,

When I do this using classic Ado I get forever all kind of ISO errors.

I make only the database with ADO and go than directly to ADONET.

Here a sample (more complete than the previous),

I hope that helps?

Cor

\\\needs that ADOX 2.7 lib for etc.
Public Class Main
Public Shared Sub Main()
Dim catNewDB As New ADOX.Catalog
Dim fi As New IO.FileInfo("c:\db1.mdb")
If fi.Exists Then
If MessageBox.Show("Delete?", "Existing File db1.mdb", _
MessageBoxButtons.YesNo) = DialogResult.Yes Then
fi.Delete()
Else
Exit Sub
End If
End If
catNewDB.Create("Provider=Microsoft.Jet.OLEDB.4.0; " & "Data
Source=C:\db1.mdb")
'To make tables we use Adonet
Dim conn As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLED B.4.0;" &
_
" Data Source=C:\db1.mdb;User Id=admin;Password=;")
Dim cmd As New OleDb.OleDbCommand("CREATE TABLE persons ( " & _
"AutoId int identity ," & _
"Id int NOT NULL," & _
"Name NVarchar(50)," & _
"BirthDate datetime," & _
"IdCountry int," & _
"CONSTRAINT [pk_AutoId] PRIMARY KEY (AutoId)) ", conn)
conn.Open()
Try
cmd.ExecuteNonQuery()
Catch ex As OleDb.OleDbException
MessageBox.Show(ex.Message, "OleDbException")
Exit Sub
Catch ex As Exception
MessageBox.Show(ex.Message, "GeneralException")
Exit Sub
End Try
cmd = New OleDb.OleDbCommand("CREATE TABLE countries ( " & _
"AutoId int identity ," & _
"Id int NOT NULL," & _
"Name NVarchar(50)," & _
"CONSTRAINT [pk_AutoId] PRIMARY KEY (AutoId)) ", conn)
Try
cmd.ExecuteNonQuery()
Catch ex As OleDb.OleDbException
MessageBox.Show(ex.Message, "OleDbException")
Exit Sub
Catch ex As Exception
MessageBox.Show(ex.Message, "GeneralException")
Exit Sub
End Try
conn.Close()
End Sub
End Class
////
Nov 21 '05 #2

P: n/a
Cor;

Thanks for that information. I'll try to adapt that to my project.

Wayne

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:uN**************@tk2msftngp13.phx.gbl...
Wayne,

When I do this using classic Ado I get forever all kind of ISO errors.

I make only the database with ADO and go than directly to ADONET.

Here a sample (more complete than the previous),

I hope that helps?

Cor

\\\needs that ADOX 2.7 lib for etc.
Public Class Main
Public Shared Sub Main()
Dim catNewDB As New ADOX.Catalog
Dim fi As New IO.FileInfo("c:\db1.mdb")
If fi.Exists Then
If MessageBox.Show("Delete?", "Existing File db1.mdb", _
MessageBoxButtons.YesNo) = DialogResult.Yes Then
fi.Delete()
Else
Exit Sub
End If
End If
catNewDB.Create("Provider=Microsoft.Jet.OLEDB.4.0; " & "Data
Source=C:\db1.mdb")
'To make tables we use Adonet
Dim conn As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLED B.4.0;" & _
" Data Source=C:\db1.mdb;User Id=admin;Password=;")
Dim cmd As New OleDb.OleDbCommand("CREATE TABLE persons ( " & _
"AutoId int identity ," & _
"Id int NOT NULL," & _
"Name NVarchar(50)," & _
"BirthDate datetime," & _
"IdCountry int," & _
"CONSTRAINT [pk_AutoId] PRIMARY KEY (AutoId)) ", conn)
conn.Open()
Try
cmd.ExecuteNonQuery()
Catch ex As OleDb.OleDbException
MessageBox.Show(ex.Message, "OleDbException")
Exit Sub
Catch ex As Exception
MessageBox.Show(ex.Message, "GeneralException")
Exit Sub
End Try
cmd = New OleDb.OleDbCommand("CREATE TABLE countries ( " & _
"AutoId int identity ," & _
"Id int NOT NULL," & _
"Name NVarchar(50)," & _
"CONSTRAINT [pk_AutoId] PRIMARY KEY (AutoId)) ", conn)
Try
cmd.ExecuteNonQuery()
Catch ex As OleDb.OleDbException
MessageBox.Show(ex.Message, "OleDbException")
Exit Sub
Catch ex As Exception
MessageBox.Show(ex.Message, "GeneralException")
Exit Sub
End Try
conn.Close()
End Sub
End Class
////

Nov 21 '05 #3

P: n/a
Cor;

You were correct, that works much more reliably. Thanks for the education.

Wayne

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:uN**************@tk2msftngp13.phx.gbl...
Wayne,

When I do this using classic Ado I get forever all kind of ISO errors.

I make only the database with ADO and go than directly to ADONET.

Here a sample (more complete than the previous),

I hope that helps?

Cor

\\\needs that ADOX 2.7 lib for etc.
Public Class Main
Public Shared Sub Main()
Dim catNewDB As New ADOX.Catalog
Dim fi As New IO.FileInfo("c:\db1.mdb")
If fi.Exists Then
If MessageBox.Show("Delete?", "Existing File db1.mdb", _
MessageBoxButtons.YesNo) = DialogResult.Yes Then
fi.Delete()
Else
Exit Sub
End If
End If
catNewDB.Create("Provider=Microsoft.Jet.OLEDB.4.0; " & "Data
Source=C:\db1.mdb")
'To make tables we use Adonet
Dim conn As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLED B.4.0;" & _
" Data Source=C:\db1.mdb;User Id=admin;Password=;")
Dim cmd As New OleDb.OleDbCommand("CREATE TABLE persons ( " & _
"AutoId int identity ," & _
"Id int NOT NULL," & _
"Name NVarchar(50)," & _
"BirthDate datetime," & _
"IdCountry int," & _
"CONSTRAINT [pk_AutoId] PRIMARY KEY (AutoId)) ", conn)
conn.Open()
Try
cmd.ExecuteNonQuery()
Catch ex As OleDb.OleDbException
MessageBox.Show(ex.Message, "OleDbException")
Exit Sub
Catch ex As Exception
MessageBox.Show(ex.Message, "GeneralException")
Exit Sub
End Try
cmd = New OleDb.OleDbCommand("CREATE TABLE countries ( " & _
"AutoId int identity ," & _
"Id int NOT NULL," & _
"Name NVarchar(50)," & _
"CONSTRAINT [pk_AutoId] PRIMARY KEY (AutoId)) ", conn)
Try
cmd.ExecuteNonQuery()
Catch ex As OleDb.OleDbException
MessageBox.Show(ex.Message, "OleDbException")
Exit Sub
Catch ex As Exception
MessageBox.Show(ex.Message, "GeneralException")
Exit Sub
End Try
conn.Close()
End Sub
End Class
////

Nov 21 '05 #4

P: n/a
On Fri, 20 Aug 2004 05:58:26 -0600, "Wayne Wengert" <wa***************@wengert.com> wrote:

I am getting an error that "object no longer valid" at the point indicated
in the code below - I am trying to build a table in an Access 2000 database
using ADOX. Any thoughts on what might cause this?

==================== code =================
Sub CreateADOUnitsTable(ByVal sTablename As String)

Dim oDB As ADOX.Catalog

Dim oUnits As ADOX.Table

oUnits = New ADOX.Table

oDB = New ADOX.Catalog

oDB.ActiveConnection = myConn

With oUnits

.Name = sTablename

You may need to add here the following line of code:

..ParentCatalog = oDB


.Columns.Append("UnitName", ADOX.DataTypeEnum.adVarWChar, 20)

.Columns.Append("Class", ADOX.DataTypeEnum.adVarWChar, 5)

.Columns.Append("Comments", ADOX.DataTypeEnum.adVarWChar, 35)

End With

oDB.Tables.Append(oUnits) '<=== Error occurs here



oUnits = Nothing

oDB = Nothing

End Sub


Paul ~~~ pc******@ameritech.net
Microsoft MVP (Visual Basic)
Nov 21 '05 #5

P: n/a
Thanks Paul, I'll try that.

Wayne

"Paul Clement" <Us***********************@swspectrum.com> wrote in message
news:cq********************************@4ax.com...
On Fri, 20 Aug 2004 05:58:26 -0600, "Wayne Wengert" <wa***************@wengert.com> wrote:
I am getting an error that "object no longer valid" at the point indicated in the code below - I am trying to build a table in an Access 2000 database using ADOX. Any thoughts on what might cause this?

==================== code =================
Sub CreateADOUnitsTable(ByVal sTablename As String)

Dim oDB As ADOX.Catalog

Dim oUnits As ADOX.Table

oUnits = New ADOX.Table

oDB = New ADOX.Catalog

oDB.ActiveConnection = myConn

With oUnits

.Name = sTablename

You may need to add here the following line of code:

.ParentCatalog = oDB


.Columns.Append("UnitName", ADOX.DataTypeEnum.adVarWChar, 20)

.Columns.Append("Class", ADOX.DataTypeEnum.adVarWChar, 5)

.Columns.Append("Comments", ADOX.DataTypeEnum.adVarWChar, 35)

End With

oDB.Tables.Append(oUnits) '<=== Error occurs here



oUnits = Nothing

oDB = Nothing

End Sub


Paul ~~~ pc******@ameritech.net
Microsoft MVP (Visual Basic)

Nov 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.