473,241 Members | 3,438 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,241 software developers and data experts.

Unspecified Error on connection.open()

Hi,

I have a question about my coding practise. I have a class method to return
a value from a database. I open the connection do my search and dispose the
reader. Open the reader with a new recordset and then close the reader and
close the connection.

I do this for every new record I am adding. But I seem to get an error
around the 770 record to add. The error is and unspecified error at the
connection.open() for that record.

Or should I be opening the connection and leave it open for all the records
I'm adding and just return to the beginning of the recordset to restart the
search?

thanks,
Will

Here is my function code:

Public Function lookupGroup(ByVal lPerson As Person) As String
Dim sConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"User ID=Admin;Data Source=" + Path.GetFullPath("EmployeeMatching.mdb")
'W:\Will\Active Directory\Export\EmployeeMatching.mdb"
Dim myReader As OleDbDataReader
Dim catCMD As New OleDbCommand
Dim schooltypecatcode As String

Try
With catCMD
..Connection = New OleDbConnection(sConnString)
..Connection.Open() <******************************
..CommandText = "Select a.schooltypecode from schooltype a, school b where
b.schoolno ='" + lPerson.dept + "' and b.schooltype = a.schooltypeid "
End With

myReader = catCMD.ExecuteReader()
If myReader.HasRows Then
myReader.Read()
schooltypecatcode = myReader.GetValue(0)
Else
schooltypecatcode = Nothing
End If
Catch ex As OleDbException
errorlog(lPerson, ex.Message, " LookupGroup OLEDB:")
Catch e As Exception
errorlog(lPerson, e.Source + ":" + e.Message, " LookupGroup Schooltype:")
Catch
errorlog(lPerson, "Unhandled Exception in schooltypecode lookup. ",
"CatchAll Exception")
Finally

If Not myReader Is Nothing Then myReader.Close()
End Try

If Not schooltypecatcode Is Nothing Then
'get the school type ie. EL for elementary
schooltypecatcode += lPerson.dept
Dim ptype = lPerson.Type
Dim pcat = lPerson.Category
Dim found As Boolean
Try
catCMD.CommandText = "SELECT c.empcatgencode, b.emptypecode,c.empcatcode,
b.emptypedesc, c.empcatdesc FROM EmpTypeCatLink a, emptype b, empcategory c
" + _
" where a.emptypeid = b.emptypeid and a.empcatid = c.empcatid"
myReader = catCMD.ExecuteReader()
Dim schooltype As String
found = False
'cycle thru the table to find the general title ie. TE for teachers
Do While myReader.Read And Not found
If (StrComp(myReader.GetValue(1), ptype) = 0 And
StrComp(myReader.GetValue(2), pcat) = 0) Then
If Not myReader.IsDBNull(0) Then
schooltypecatcode += myReader.GetValue(0)
found = True
Else
schooltypecatcode = Nothing
found = True
End If
End If
Loop
Catch ex As Exception
errorlog(lPerson, ex.Source + ":" + ex.Message, "Lookup Group
Empcatgencode:")
Catch
errorlog(lPerson, "Unhandled Exception: EmpCatGenCode lookup ", "CatchAll
Exception")
Finally
If Not myReader Is Nothing Then myReader.Close()
End Try
End If
If Not catCMD Is Nothing Then catCMD.Dispose()
Return schooltypecatcode
Jul 21 '05 #1
6 2519
wk6pack <wk***@sd61.bc.ca> wrote:
I have a question about my coding practise. I have a class method to return
a value from a database. I open the connection do my search and dispose the
reader. Open the reader with a new recordset and then close the reader and
close the connection.

I do this for every new record I am adding. But I seem to get an error
around the 770 record to add. The error is and unspecified error at the
connection.open() for that record.

Or should I be opening the connection and leave it open for all the records
I'm adding and just return to the beginning of the recordset to restart the
search?


I can't see where you're closing the connection. You're disposing of
the command and closing the reader, but not closing the connection.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #2
Hi Jon,

I thought that when I dispose of the object, it would close the connection?
So if that is not the case, I was opening too many connections and it gave
me an error then?

thanks,
Will

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
wk6pack <wk***@sd61.bc.ca> wrote:
I have a question about my coding practise. I have a class method to return a value from a database. I open the connection do my search and dispose the reader. Open the reader with a new recordset and then close the reader and close the connection.

I do this for every new record I am adding. But I seem to get an error
around the 770 record to add. The error is and unspecified error at the
connection.open() for that record.

Or should I be opening the connection and leave it open for all the records I'm adding and just return to the beginning of the recordset to restart the search?


I can't see where you're closing the connection. You're disposing of
the command and closing the reader, but not closing the connection.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Jul 21 '05 #3
wk6pack <wk***@sd61.bc.ca> wrote:
I thought that when I dispose of the object, it would close the connection?
Which object do you mean? Disposing of a command doesn't close the
connection.
So if that is not the case, I was opening too many connections and it gave
me an error then?


Yes, that's probably the problem.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #4
Hi Jon,

I thought disposing of the any object would close the connection. I'll
remember that.

thanks,
Will
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP***********************@msnews.microsoft.co m...
wk6pack <wk***@sd61.bc.ca> wrote:
I thought that when I dispose of the object, it would close the connection?

Which object do you mean? Disposing of a command doesn't close the
connection.
So if that is not the case, I was opening too many connections and it

gave me an error then?


Yes, that's probably the problem.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Jul 21 '05 #5
disposing of the connection object implicitly closes the connection so you
don't have to do it there

--
Regards,
Alvin Bruney
[Shameless Author Plug]
The Microsoft Office Web Components Black Book with .NET
available at www.lulu.com/owc
_________________________
"wk6pack" <wk***@sd61.bc.ca> wrote in message
news:Oj**************@TK2MSFTNGP14.phx.gbl...
Hi Jon,

I thought disposing of the any object would close the connection. I'll
remember that.

thanks,
Will
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP***********************@msnews.microsoft.co m...
wk6pack <wk***@sd61.bc.ca> wrote:
> I thought that when I dispose of the object, it would close the connection?

Which object do you mean? Disposing of a command doesn't close the
connection.
> So if that is not the case, I was opening too many connections and it

gave > me an error then?


Yes, that's probably the problem.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


Jul 21 '05 #6
wk6pack <wk***@sd61.bc.ca> wrote:
I thought disposing of the any object would close the connection. I'll
remember that.


Disposing of the *connection* will close it - but you've only disposed
the command.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: rOadhOg | last post by:
Help please! I set up a simple access 2000 database and I'm running IIS5. The first time I try it, it works, then it seems like I have to wait for some kind of time out for it to work again,...
2
by: Jim Lacenski | last post by:
I have a VB class that uses .NET and ADODB to write into an Excel spreadsheet (via Jet) on a server as part of a web application. ADODB is used instead of ADO.NET because it greatly simplifies the...
4
by: Troy | last post by:
We recently installed the .Net framework on a windows 2000 server. Shortly after that we experienced intermitant problems running a web based program that accesses an Access 2002 database. The...
7
by: Jim McGivney | last post by:
ASPX page from VS.net-C# on host's computer using oleDataAdaptor to connect to Microsoft Access database. The page loads, but when connection to the database is attempted to fill a datagrid the...
3
by: Jerry Spence1 | last post by:
I am starting up a number of threads. Each one specifies a connection to the same database. Sub ReaderThread() Dim cn As New System.Data.OleDb.OleDbConnection cn.ConnectionString =...
6
by: wk6pack | last post by:
Hi, I have a question about my coding practise. I have a class method to return a value from a database. I open the connection do my search and dispose the reader. Open the reader with a new...
1
by: abcd | last post by:
I am using MSAccess 2003 as my DB, ASP page my front end. My access file is in the temp folder which ahs IUSR_Machine permissions. My asp page works fine, connects to DB and retrieves what I...
0
by: fniles | last post by:
I am using VB.Net 2003 and MS Access database. Sometimes when I open the database, I got the error "Unspecified error" The application validate users, when it validates users, it reads from a...
0
ammoos
by: ammoos | last post by:
hi friends I am facing one problem while trying to open connection of Oledb Data for excel. I am getting the error "System.Data.OleDb.OleDbException: Unspecified error " i am using the code ...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.