Wierd thing data is there twice

Qbert

Active member
Joined
Jun 11, 2007
Messages
33
Location
Minnesota
Programming Experience
Beginner
i have a form with a list box on it and it displays records from the database. when i open the form it is fine. then if i close the form and reopen it the data is there twice. i dont know why. if anyone can look at it and maybe see where i am making my mistake that would be great.

it also wont delete the record. which is weird because it used to delete it.

thanks

here is the code

VB.NET:
Public Class ClientList
    Dim ClientIDArray() As Integer
    Dim ClientNameArray() As String

    Private Sub CloseToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles CloseToolStripMenuItem.Click
        Me.Close()
    End Sub

    Private Sub ClientList_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        IanConnect.Open()

        Dim ClientList As New System.Data.OracleClient.OracleCommand

        ClientList.Connection = IanConnect
        ClientList.CommandText = "select * from clients order by client_name"

        Dim dr As System.Data.OracleClient.OracleDataReader = ClientList.ExecuteReader()
        Dim counter As Integer = 0

        While dr.Read()
            ClientListListBox.Items.Add(dr.Item(1))
            ReDim Preserve ClientIDArray(counter + 1)
            ReDim Preserve ClientNameArray(counter + 1)
            ClientIDArray(counter) = dr.Item(0)
            ClientNameArray(counter) = dr.Item(1)
            counter += 1
        End While

        IanConnect.Close()
    End Sub

    Private Sub EditClientToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles EditClientToolStripMenuItem.Click
        Dim FormB As New EditClient()

        If ClientListListBox.SelectedIndex = -1 Then
            MsgBox("Please select a client to edit")
        Else
            PassedClientID = ClientIDArray(ClientListListBox.SelectedIndex)
            EditClient.ShowDialog()
            'Me.Close()
        End If
    End Sub

    Private Sub DeleteClientToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles DeleteClientToolStripMenuItem.Click
        If ClientListListBox.SelectedIndex = -1 Then
            'do nothing
        Else
            PassedClientID = ClientIDArray(ClientListListBox.SelectedIndex)
            PassedClientName = ClientNameArray(ClientListListBox.SelectedIndex)

            MsgBox("Delete Client """ & PassedClientName & """?", MsgBoxStyle.YesNo)

            If MsgBoxResult.No Then
                'do nothing
            ElseIf MsgBoxResult.Yes Then

                IanConnect.Open()

                Dim DeleteClient As New System.Data.OracleClient.OracleCommand
                DeleteClient.Connection = IanConnect
                DeleteClient.CommandText = "DELETE from CLIENTS where CLIENT_ID = " & PassedClientID

                Delete = DeleteClient.ExecuteNonQuery()

                If Delete > 0 Then
                    MsgBox("Client " & PassedClientName & "  Deleted")
                    Me.Refresh()
                Else
                    MsgBox("No")
                End If

                IanConnect.Close()

            End If
        End If
    End Sub
End Class
 
Last edited by a moderator:
The only reason I could think of would be that you are either not clearing out the array or dataset that you are using to populate the listbox or that for some reason the listbox is not being cleared out. Just try a few different combinations of clearing out the dataset and arrays you use in the class. On closing the form you should clear out these objects and possibly before loading the data you should clear out the dataset or data reader as I am not too familiar with the oracle connection objects.


Steve
 
Oooh.. we dont do data access like that any more. Have a read of DW2 in my signature, section on Createing a Simple App
 
i looked at the DW2 that you suggested and i was unable to figure it out. it always talked about adding a data source. i am unable to add a data source for some reason. but when i use a connection string i am able to connect to the database and get data out and insert data.

here is what i am using to connect to my database.

VB.NET:
    Public DBConn As String = "Data Source=(DESCRIPTION=(ADDRESS_LIST=" _
                + "(ADDRESS=(PROTOCOL=TCP)(HOST=10.0.0.99)(PORT=1521)))" _
                + "(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=XE)));" _
                + "User Id=minnow;Password=asdfasdf;"
    Public IanConnect As New System.Data.OracleClient.OracleConnection(DBConn)

the database is located on a server and when i try to add a data source i am unable to conect.
 
Your connection string is missing the Provider, which isnt going to get you off to a great start..

There are guides in DW2 for conencting to Oracle. Using TNS will make your life easier
 
when ever i try to add a data source i get this error

ORA-12514: TNS:listener does not currently know of service requested in connect decriptor

here is my tns info:

VB.NET:
XE =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 10.0.0.99)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = XE)
    )
  )

and i created a listener:

VB.NET:
LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 10.0.0.99)(PORT = 1521))
    )
  )

someone also posted elsewhere that i should not use TNS
 
I dont think the listener is needed for you to make outbound requests. I suggest you set the TNS up using the network admin tool, and test and ensure it works there first. Remember that the default host name in the SQLNet.ora can affect where your connect descriptors point
 
using the net configuration assistant i am able to connect just fine.

here is my SQLNet.ora

VB.NET:
# sqlnet.ora Network Configuration File: C:\oracle\product\10.2.0\client_2\network\admin\sqlnet.ora
# Generated by Oracle configuration tools.

# This file is actually generated by netca. But if customers choose to 
# install "Software Only", this file wont exist and without the native 
# authentication, they will not be able to connect to the database on NT.

SQLNET.AUTHENTICATION_SERVICES= (NTS)

NAMES.DIRECTORY_PATH= (TNSNAMES)
 
sure i will post all i have.

listener.ora
VB.NET:
# listener.ora Network Configuration File: C:\oracle\product\10.2.0\client_2\NETWORK\ADMIN\listener.ora
# Generated by Oracle configuration tools.

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (SID_NAME = PLSExtProc)
      (ORACLE_HOME = C:\oracle\product\10.2.0\client_2)
      (PROGRAM = extproc)
    )
  )

LISTENER =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 10.0.0.99)(PORT = 1521))
  )

tnsnames.ora
VB.NET:
# tnsnames.ora Network Configuration File: C:\oracle\product\10.2.0\client_2\network\admin\tnsnames.ora
# Generated by Oracle configuration tools.

XE =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 10.0.0.99)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = XE)
    )
  )

EXTPROC_CONNECTION_DATA =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))
    )
    (CONNECT_DATA =
      (SID = PLSExtProc)
      (PRESENTATION = RO)
    )
  )

sqlnet.ora
VB.NET:
# sqlnet.ora Network Configuration File: C:\oracle\product\10.2.0\client_2\network\admin\sqlnet.ora
# Generated by Oracle configuration tools.

# This file is actually generated by netca. But if customers choose to 
# install "Software Only", this file wont exist and without the native 
# authentication, they will not be able to connect to the database on NT.

SQLNET.AUTHENTICATION_SERVICES= (NTS)

NAMES.DIRECTORY_PATH= (TNSNAMES)
 
None of your files seem to list default domains

i'm on a network where the default domain is bobble.com:

VB.NET:
# sqlnet.ora Network Configuration File: C:\oracle\product\10.2.0\client\NETWORK\ADMIN\sqlnet.ora
# Generated by Oracle configuration tools.

SQLNET.AUTHENTICATION_SERVICES= (NONE)

NAMES.DIRECTORY_PATH= (TNSNAMES)

NAMES.DEFAULT_DOMAIN = [B]bobble.com[/B]


VB.NET:
# tnsnames.ora Network Configuration File: C:\oracle\product\10.2.0\client\NETWORK\ADMIN\tnsnames.ora
# Generated by Oracle configuration tools.

LIVE01.[B]bobble.com [/B]=
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = ORACLE1)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = [B]ORALIVE.COM[/B])
    )
  )

Note that the service name differs here.. the alias Live01 links to a database instance that is named ORALIVE.COM

The db admin can tell you the service name


I get the feeling that:
You havent specified a default domain
A default domain is being assumed (.com?? i dont know)
Your TNS aliases have no domain names appended
When you attempt to connect to XE, the default domain is appended (XE.com) and no alias matches XE.COM (its called XE)


Try adding the default domain line to your sqlnet
Also add it to the aliases in tnsnames
You too can use bobble.com if you want. It need not be related to the network youre on
 
I note also your oracle is installed to client_2

Why?


Me: C:\oracle\product\10.2.0\client\NETWORK\ADMIN\tnsnames.ora
You: C:\oracle\product\10.2.0\client_2\NETWORK\ADMIN\tnsnames.ora

Have you got other clients installed? Confusion?
 
so i added the domain to the places you said. and now i get a different error. i think i am getting close.

it said

TNS: could not resolve the connect identifier specified

i dont know why it is installed there. i am going to try to reinstall it.

one thing i dont understand is why can i connect and get data from the database even though i havent set up a datasource? but by using this i can.

VB.NET:
Public DBConn As String = "Data Source=(DESCRIPTION=(ADDRESS_LIST=" _
                + "(ADDRESS=(PROTOCOL=TCP)(HOST=10.0.0.99)(PORT=1521)))" _
                + "(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=XE)));" _
                + "User Id=minnow;Password=asdfasdf;"
    Public IanConnect As New System.Data.OracleClient.OracleConnection(DBConn)
 
thank you very much for the help. i reinstalled the oracle client into the same location as you and now it works no problem.

now lets see if my problem of double data goes away.
 
i think i am connecting the wrong way. is there some way that i should be connecting? the data is still showing up twice.

i was able to create a dataset. called ClientListDataSet.xsd.

do i want to use that somehow?
 
Back
Top