database problems

G

Guest

I am using oracle, not by choice. I am getting some errors that I can't debug.

I have my db stuff in a module with public functions named database.vb

Then I am trying to call the function from a form like this:

Private Sub Main_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim iPortNumber As Short

iPortNumber = CType(GetPortNumber(glbstrAssistLogin), Short)

End Sub

I am getting a big error on debug that I won't even try and type here. My
question is should I approach it like this or should I have a connection on
any form that I use a connection on. That seems wasteful but I am missing
something. The connection string is correct because I can use it on a page
that has it's own connection.

Thanks for any advice
Mike





database.vb:
------------------------------------------------------------------------
Imports System.Data.OracleClient

Module database
Public oraConn As New System.Data.OracleClient.OracleConnection


Public Function OpenOradb(ByVal str As String)
oraConn.ConnectionString = str
oraConn.Open()
End Function

Public Function CloseOradb()
oraConn.Close()
End Function

Public Function GetPortNumber(ByVal str As String) As String
Dim oraComm1 As New System.Data.OracleClient.OracleCommand
OpenOradb(str)
CloseOradb()

Return 2
End Function

Public Function GetBalanceID(ByVal str As String) As String

Return "Boo"
End Function
End Module
 
J

Jon Skeet [C# MVP]

Mike D said:
I am using oracle, not by choice. I am getting some errors that I can't debug.

I have my db stuff in a module with public functions named database.vb

Then I am trying to call the function from a form like this:

Private Sub Main_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim iPortNumber As Short

iPortNumber = CType(GetPortNumber(glbstrAssistLogin), Short)

End Sub

I am getting a big error on debug that I won't even try and type here. My
question is should I approach it like this or should I have a connection on
any form that I use a connection on. That seems wasteful but I am missing
something. The connection string is correct because I can use it on a page
that has it's own connection.

You should use a separate connection for each thing that you want to
do. Connection pooling will take care of the *real* underlying
connections.

Note that you should use try/finally to make sure that you *always*
close the connection, not just if you don't get any exceptions.
 
G

Guest

Thanks for the reply. I have not been using Try ... Finally but will look
into it.

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top