Creating Oracle Connection causes error in COM class retrieval - vb.net

I am writing an application in VB.NET that requires that I query an Oracle database using the Oracle Data Access Client. I then use something called the SCAPI interface to access the metadata of an application we use for data modeling.
I've simplified the problem down to just two functions that are executed by clicking buttons on a form.
This function is executed when I click a button on the form. It creates an oracle connection but doesn't actually execute any queries (because I've commented the rest out and still get the error):
Private Sub btnDisplayDirectories_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplayDirectories.Click
Dim ModelMart As String = "Data Source=...;User Id=...;Password=...;"
Dim OraConn As New OracleConnection(ModelMart)
OraConn.Open()
OraConn.Close()
OraConn.Dispose()
End Function
This function just creates the application object using the SCAPI interface:
Private Sub btnOpenModel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpenModel.Click
Dim oAPI As New SCAPI.Application
End Sub
There is no issue if I fire up the application, and click on btnOpenModel first, then click on btnDisplayDirectories. If I click on btnDisplayDirectories, then I click on btnOpenModel, I get an error on the first line of btnOpenModel that says:
Retrieving the COM class factory for component with CLSID {2B2219EB-EDE7-49EE-BB89-5A0B4A398A63} failed due to the following error: 80004005.
I've actually experimented and I don't even have to open the Oracle connection to get this error, just defining the Oracle Connection causes the error.

I solved the problem by creating the SCAPI.Application object as a global variable. This causes SCAPI to get its hands on whatever resources it requires before the database objects do. I wasn't able to figure out exactly why SCAPI and Oracle/ODBC assemblies don't play nice with each other.

Related

Unable to add rows to datatable, datatable is nothing error

I am not really sure what went wrong, i declared dt on top as a class variable then declare it as new datatable in fill function used in pageload but when i pressed buttonadd, dt is nothing error pops up.
Private dt As DataTable
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
fill()
End If
End Sub
Protected Sub fill()
dt = New DataTable
dt.Columns.Add("Status", GetType(String))
End Sub
Protected Sub btnadd_Click(sender As Object, e As EventArgs) Handles btnadd.Click
Dim R As DataRow = dt.NewRow
R("Status") = "Pending"
dt.Rows.Add(R)
'dt.Rows.Add("pending")
GridView1.DataSource = dt
GridView1.DataBind()
End Sub
The key concept is that web pages are "state-less".
That means for each event code stub, then the code is starting over from scratch.
And it means for each browser round trip, then the browser code starts from scratch EACH time. So, you only load up the data table one time (first time - this is GOOD!!!).
The problem of course, without a control on the web page. (say a data grid), or say a simple text box? Those controls survive that so called round trip. The MOST important concept, and if were going to learn ONE thing about asp.net web pages?
You must grasp the round trip concept, and the so called page state.
So, what happens in your case?
First time - page loads - code runs server side (often called code behind).
Your form instance class is created, your load event runs, you load up the table. The browser is THEN send down to the client side. The web page is just sitting here. Maybe you close the browser. Maybe you un-plug your computer. The server does not know, or care about this. In fact, the server does NOT even know the web page exists anymore!!!
So, your web page is sitting here, and you click on that button.
The web page is now sent up to the server, and the code behind starts running - but it STARTS FROM FRESH scratch each time!
So your form level variable called "data table" does NOT exist any more and does NOT have a value.
So, there are several solutions here. For starters, we need that "table" to persist and survive the rounds trip. As noted, most controls you drop into that page WILL keep their values. This is called the "viewstate". So, if we want that data table to survive and "exist" the next time the user does something? Then we need to save or persist that table variable.
Another way? You can use what is called the session(). Session() is a attempt and system to allow use to shove values into Session(). And the session() survives round trips.
Now, given your example?
Well, then our code would become this:
Private dt As DataTable
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
fill()
Session("MyCoolTable") = dt
else
' this is a page post back - re-load the active table into our
' forms level dt.
dt = Session("MyCoolTable")
end if
In a lot of cases, I would assume the table that drives the grid is a database. And thus I would add the row to the database, and then re-bind the data grid.
But the above use of session() will persist the dt table for you.

How to save, edit, and create new record in Access Query with VB.NET

I have a task from school to make a simple program with VB.NET and currently having an issue now. I've connected my MS Access Query (Query, not Table) with my form in VS2015. The program run smoothly, but when I want to update the data, this error message came up
TableAdapterManager contains no connection information. Set each TableAdapterManager TableAdapter property to a valid TableAdapter instance.
I used this following code to update the database
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Me.Validate()
Me.JoblistBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.Joblist)
End Sub
I need this program to run as late as Thursday.
Does anyone know how to fix this problem? Thanks before.

Access database connecting to VS but no data showing and runtime error

Trying to use an access database with Visual studio 15. After failure I found a number of tutorials and followed them with a new project and new database.
The database is connecting but the data inside the database won't display (although no error) and even using the built in save function in VB results in a run time error.
If anyone can point me in the right direction I'd be grateful. Code below.
Public Class Form1
Private Sub CustomersBindingNavigatorSaveItem_Click(sender As Object, e As EventArgs) Handles CustomersBindingNavigatorSaveItem.Click
Me.Validate()
Me.CustomersBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.CustomersDataSet) 'Error is here****
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'CustomersDataSet.Customers' table. You can move, or remove it, as needed.
Me.CustomersTableAdapter.Fill(Me.CustomersDataSet.Customers)
End Sub
Private Sub BindingNavigatorDeleteItem_Click(sender As Object, e As EventArgs) Handles BindingNavigatorDeleteItem.Click
End Sub
Private Sub BindingNavigatorAddNewItem_Click(sender As Object, e As EventArgs) Handles BindingNavigatorAddNewItem.Click
End Sub
End Class
The error message I get is An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll
Additional information: Unspecified error.
Here is a video that I made a while ago that should be able to help you, If you have any questions about it, i can definitely help you out.
https://www.youtube.com/watch?v=vvzY0LsAUNE
Also do you definitely need to use Access? I would recommend using an SQL database because when you publish your program, the end user may have to have a link to your access database in the same spot as yours, which can be a pain.
Nevertheless here is a video i also made regarding setting up an SQL database via Visual Studio.
https://www.youtube.com/watch?v=NLs44hxV514
If you have any issue, leave a comment and i will be happy to help you out :)
Keep In Mind
Don't forget that you need to also have a Number/unique word/or something a like in the Primary key column even if you haven't added any details to the database. eg Name and so on. If not your program may crash, so you could use the Try statement to fix this issue if the Primary Key column is left empty.

VB 2013 Persistent User Settings

On my form I have a menu with "file-save". When I click save I want to save particular settings to restore when the form is closed and re-opened. I've done this successfully for text in text-boxes and the checked states of check-boxes, but I'm failing when trying to loop through the items in a list-box. Please see below for what I've tried...
When I click save:
Private Sub SaveToolStripMenuItem_Click(sender As Object, e As EventArgs)
Handles SaveToolStripMenuItem.Click
For Each i In ListBox1.Items()
My.Settings.ListBox1.Add(i)
Next
My.Settings.Save()
End Sub
When my form loads:
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
For Each i In My.Settings.ListBox1()
ListBox1.Items.Add(i)
Next
End Sub
I've only been using VB for three days, so apologies if I am missing something simple ha! Thanks for any help!!!
There is one small glitch with the StringCollection in settings. If you do not seed it with a fake variable then it starts out as Nothing and you cannot add to Nothing. in your form load add this:
' if the collection has not been initialized, do so
If My.Settings.ListBox1 Is Nothing Then
My.Settings.ListBox1= New System.Collections.Specialized.StringCollection
End If
' now it is safe to use: load strings from Setting -> form listbox
For Each s As String In My.Settings.ListBox1()
ListBox1.Items.Add(s)
Next
The very first time it runs, there are likely no saved settings, so we have to create the container for them, basically.
Option Strict can be implemented by file, by adding this at the top:
Option Strict On
Or for the project: Project => Properties => Compile: Option Strict is likely to the right (I have 2012). You can also set it as a permanent option (recommended).
Among other things, this will prevent you from plucking variables out of the air and use them without declaring a type (which will lead to errors). For instance:
For Each i In My.Settings.ListBox1()
becomes
For Each s As String In My.Settings.ListBox1() ' tell the compiler the Type

Simple, but I'm stuck ....Updating a DataSet using code

I have a simple Windows form in VB: textbox bound thru an adapter and a bindingsource to my dataset.
I have a button that on Click I want it to update the database. The form loads and the first data row shows in the textbox, I change the text then click my button but no update happens.
Any ideas what I'm doing wrong, or how I should do this??
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.AToolsTableAdapter.Fill(Me.Qedsandb_TroyDataSet.aTools)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
AToolsTableAdapter.Update(Qedsandb_TroyDataSet.aTools)
End Sub
End Class
Assuming the click event runs(?), TableAdapters based on a query (a join) do not, by default, have the ability to update the database. The name of your binding source suggests that you are using a query.
MSDN: TableAdapter Overview
The update functionality of a TableAdapter is dependent on how much
information is available based on the main query provided in the
TableAdapter Wizard. For example, TableAdapters that are configured to
fetch values from multiple tables (JOINs), scalar values, views, or
the results of aggregate functions are not initially created with the
ability to send updates back to the underlying database. However, you
can configure the INSERT, UPDATE and DELETE commands manually in the
Properties window.
You don't appear to be moving the data back from the form to the dataset. Try calling EndEdit on your bindingsource.