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 CreateADOUnitsT able(ByVal sTablename As String)
Dim oDB As ADOX.Catalog
Dim oUnits As ADOX.Table
oUnits = New ADOX.Table
oDB = New ADOX.Catalog
oDB.ActiveConne ction = myConn
With oUnits
..Name = sTablename
..Columns.Appen d("UnitName", ADOX.DataTypeEn um.adVarWChar, 20)
..Columns.Appen d("Class", ADOX.DataTypeEn um.adVarWChar, 5)
..Columns.Appen d("Comments", ADOX.DataTypeEn um.adVarWChar, 35)
End With
oDB.Tables.Appe nd(oUnits) '<=== Error occurs here
oUnits = Nothing
oDB = Nothing
End Sub 5 2082
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", _
MessageBoxButto ns.YesNo) = DialogResult.Ye s Then
fi.Delete()
Else
Exit Sub
End If
End If
catNewDB.Create ("Provider=Micr osoft.Jet.OLEDB .4.0;" & "Data
Source=C:\db1.m db")
'To make tables we use Adonet
Dim conn As New OleDb.OleDbConn ection("Provide r=Microsoft.Jet .OLEDB.4.0;" &
_
" Data Source=C:\db1.m db;User Id=admin;Passwo rd=;")
Dim cmd As New OleDb.OleDbComm and("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.ExecuteNonQ uery()
Catch ex As OleDb.OleDbExce ption
MessageBox.Show (ex.Message, "OleDbException ")
Exit Sub
Catch ex As Exception
MessageBox.Show (ex.Message, "GeneralExcepti on")
Exit Sub
End Try
cmd = New OleDb.OleDbComm and("CREATE TABLE countries ( " & _
"AutoId int identity ," & _
"Id int NOT NULL," & _
"Name NVarchar(50)," & _
"CONSTRAINT [pk_AutoId] PRIMARY KEY (AutoId)) ", conn)
Try
cmd.ExecuteNonQ uery()
Catch ex As OleDb.OleDbExce ption
MessageBox.Show (ex.Message, "OleDbException ")
Exit Sub
Catch ex As Exception
MessageBox.Show (ex.Message, "GeneralExcepti on")
Exit Sub
End Try
conn.Close()
End Sub
End Class
////
Cor;
Thanks for that information. I'll try to adapt that to my project.
Wayne
"Cor Ligthert" <no**********@p lanet.nl> wrote in message
news:uN******** ******@tk2msftn gp13.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", _ MessageBoxButto ns.YesNo) = DialogResult.Ye s Then fi.Delete() Else Exit Sub End If End If catNewDB.Create ("Provider=Micr osoft.Jet.OLEDB .4.0;" & "Data Source=C:\db1.m db") 'To make tables we use Adonet Dim conn As New OleDb.OleDbConn ection("Provide r=Microsoft.Jet .OLEDB.4.0;"
& _ " Data Source=C:\db1.m db;User Id=admin;Passwo rd=;") Dim cmd As New OleDb.OleDbComm and("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.ExecuteNonQ uery() Catch ex As OleDb.OleDbExce ption MessageBox.Show (ex.Message, "OleDbException ") Exit Sub Catch ex As Exception MessageBox.Show (ex.Message, "GeneralExcepti on") Exit Sub End Try cmd = New OleDb.OleDbComm and("CREATE TABLE countries ( " & _ "AutoId int identity ," & _ "Id int NOT NULL," & _ "Name NVarchar(50)," & _ "CONSTRAINT [pk_AutoId] PRIMARY KEY (AutoId)) ", conn) Try cmd.ExecuteNonQ uery() Catch ex As OleDb.OleDbExce ption MessageBox.Show (ex.Message, "OleDbException ") Exit Sub Catch ex As Exception MessageBox.Show (ex.Message, "GeneralExcepti on") Exit Sub End Try conn.Close() End Sub End Class ////
Cor;
You were correct, that works much more reliably. Thanks for the education.
Wayne
"Cor Ligthert" <no**********@p lanet.nl> wrote in message
news:uN******** ******@tk2msftn gp13.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", _ MessageBoxButto ns.YesNo) = DialogResult.Ye s Then fi.Delete() Else Exit Sub End If End If catNewDB.Create ("Provider=Micr osoft.Jet.OLEDB .4.0;" & "Data Source=C:\db1.m db") 'To make tables we use Adonet Dim conn As New OleDb.OleDbConn ection("Provide r=Microsoft.Jet .OLEDB.4.0;"
& _ " Data Source=C:\db1.m db;User Id=admin;Passwo rd=;") Dim cmd As New OleDb.OleDbComm and("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.ExecuteNonQ uery() Catch ex As OleDb.OleDbExce ption MessageBox.Show (ex.Message, "OleDbException ") Exit Sub Catch ex As Exception MessageBox.Show (ex.Message, "GeneralExcepti on") Exit Sub End Try cmd = New OleDb.OleDbComm and("CREATE TABLE countries ( " & _ "AutoId int identity ," & _ "Id int NOT NULL," & _ "Name NVarchar(50)," & _ "CONSTRAINT [pk_AutoId] PRIMARY KEY (AutoId)) ", conn) Try cmd.ExecuteNonQ uery() Catch ex As OleDb.OleDbExce ption MessageBox.Show (ex.Message, "OleDbException ") Exit Sub Catch ex As Exception MessageBox.Show (ex.Message, "GeneralExcepti on") Exit Sub End Try conn.Close() End Sub End Class ////
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 CreateADOUnitsT able(ByVal sTablename As String)
¤
¤ Dim oDB As ADOX.Catalog
¤
¤ Dim oUnits As ADOX.Table
¤
¤ oUnits = New ADOX.Table
¤
¤ oDB = New ADOX.Catalog
¤
¤ oDB.ActiveConne ction = myConn
¤
¤ With oUnits
¤
¤ .Name = sTablename
You may need to add here the following line of code:
..ParentCatalog = oDB
¤
¤ .Columns.Append ("UnitName", ADOX.DataTypeEn um.adVarWChar, 20)
¤
¤ .Columns.Append ("Class", ADOX.DataTypeEn um.adVarWChar, 5)
¤
¤ .Columns.Append ("Comments", ADOX.DataTypeEn um.adVarWChar, 35)
¤
¤ End With
¤
¤ oDB.Tables.Appe nd(oUnits) '<=== Error occurs here
¤
¤
¤
¤ oUnits = Nothing
¤
¤ oDB = Nothing
¤
¤ End Sub
¤
Paul ~~~ pc******@amerit ech.net
Microsoft MVP (Visual Basic)
Thanks Paul, I'll try that.
Wayne
"Paul Clement" <Us************ ***********@sws pectrum.com> wrote in message
news:cq******** *************** *********@4ax.c om... 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 CreateADOUnitsT able(ByVal sTablename As String) ¤ ¤ Dim oDB As ADOX.Catalog ¤ ¤ Dim oUnits As ADOX.Table ¤ ¤ oUnits = New ADOX.Table ¤ ¤ oDB = New ADOX.Catalog ¤ ¤ oDB.ActiveConne ction = myConn ¤ ¤ With oUnits ¤ ¤ .Name = sTablename
You may need to add here the following line of code:
.ParentCatalog = oDB
¤ ¤ .Columns.Append ("UnitName", ADOX.DataTypeEn um.adVarWChar, 20) ¤ ¤ .Columns.Append ("Class", ADOX.DataTypeEn um.adVarWChar, 5) ¤ ¤ .Columns.Append ("Comments", ADOX.DataTypeEn um.adVarWChar, 35) ¤ ¤ End With ¤ ¤ oDB.Tables.Appe nd(oUnits) '<=== Error occurs here ¤ ¤ ¤ ¤ oUnits = Nothing ¤ ¤ oDB = Nothing ¤ ¤ End Sub ¤
Paul ~~~ pc******@amerit ech.net Microsoft MVP (Visual Basic) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: JBAdamsJr |
last post by:
I want to be able to create an Excel file with a VB.NET program on a server that does not have Microsoft Excel loaded on it. I am using the Jet OLE DB to read other data files. Can this be used to save an array in an Excel .XLS format?
|
by: KemperR |
last post by:
Hello Experts outhere,
may be someone can tell me whats going wrong with my ADOX trial.
I have an Access 2002 database with some tables and queries (views)
The code listed below works well up to the point where I want to add
the new view to the views collection. I get Runtime error 3001 which
is telling me
"Arguments are of wrong type,are out of acceptable range or conflict
with one another"
|
by: Gandalf |
last post by:
I'm creating relationships between tables using VBA and ADOX. I can
create one-to-one relationships with an inner join, but I can't figure
out how to create these relationships with an outer join (specifically
a left outer join). I'm including the code that creates the
relationships with the inner join. Any help or suggestions would be
greatly appreciated.
Thanks!
<----- CODE FOLLOWS ----->
|
by: Claudia Fong |
last post by:
Hello,
I'm using the sql statement below to create a new table from an old one.
But I found a little problem with that.
In my old table DEP2004, I have one field's property allow zero length
is YES, but after creating the new table DEP2005, this property change
to NO. It means it won't allow zero lenght.. How can I change this
property in C#?
|
by: Wayne Wengert |
last post by:
I am trying to create a VB.NET Windows application to move some data from a
local Access DB table to a table in a SQL Server. The approach I am trying
is to open an OLEDB connection to the local Access DB and then add a Linked
Table pointing to the table on the SQL Server and then run an "Insert Into
(linked table)" query to add the new rows.
I am having a problem getting the syntax to add that linked table to my
local Access DB. When I...
| |
by: Steven Smith |
last post by:
Hello all,
I have a vb6 (not .NET) program using MS Access as the backend. As part of
an import form, I need to allow the user to select the table containing the
data to be imported. How can I populate a combo with this information?
Then, once this value is selected, how can I populate other combos with the
column names of the selected table?
Thanks,
|
by: C# Beginner |
last post by:
Hi there,
I'm currently trying to create a MS access file at runtime, but I stumble
into some problems.
1. When I use Datatype adUnsignedInt I get an error (invalid type).
2. Which datatype must I use to create an autonumbering field?
3. Which datatype must I use to create an OLE-object field?
I'm currently using Microsoft ActiveX Data Objects Library 2.8 and using
engine type 5.
|
by: Bhavsan |
last post by:
Here is what I am trying to do. Kindly, help me.
1. I'm creating a query dynamically based on User input using VBA
(strSQL and DotSQL in the code below)
2. Executing the created query with in VBA
3. Writing to a table (tblRandom) the values from the recordset.
--------------------------------
Private Sub append_record_Click()
Dim strSQL As String
Dim dotsql As String
|
by: Vee007 |
last post by:
Following is my code:
Dim objCatalog As ADOX.Catalog
Dim objTableLink As ADOX.Table
Dim objADOConnection As ADODB.Connection
Try
objADOConnection = New ADODB.Connection
objADOConnection.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Database\abc.mdb;User Id=admin;Password=;")
objCatalog = New ADOX.Catalog
objCatalog.ActiveConnection = objADOConnection
...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |