473,396 Members | 1,676 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,396 software developers and data experts.

Recordset closes for no reason

Hi,

I am using vb.net and sql2000.
I am running a sql statement using a udl to connect to the database.
Throuhg one sub, several sql statements are executed against the udl's cn and I just reuse the rs to hold the next result set.

My problem is that through a few statements this works fine - I can use "With rs" and set up a cycle to loop through the rs to confirm data returned. But when I reach one of them (they are the same except for the sql statement passed) the rs closes unexpectedly and I cannot see the data within it hence it then returns an error stating the rs is closed.

Any ideas why it might be doing this? I am not telling the rs too clsoe anywhere in my code (yet).

Cheers
Adam

Nov 21 '05 #1
15 1257
You should be using a dataset not a recordset in VB.NET.

If you are using a recordset though using ADO and not ADO.NET, then verify what type of cursor you are using.

--
Gerry O'Brien [MVP]
Visual Basic .NET(VB.NET)


"Adam Maltby" <ad***@frfl.co.uk> wrote in message news:O%******************@TK2MSFTNGP11.phx.gbl...
Hi,

I am using vb.net and sql2000.
I am running a sql statement using a udl to connect to the database.
Throuhg one sub, several sql statements are executed against the udl's cn and I just reuse the rs to hold the next result set.

My problem is that through a few statements this works fine - I can use "With rs" and set up a cycle to loop through the rs to confirm data returned. But when I reach one of them (they are the same except for the sql statement passed) the rs closes unexpectedly and I cannot see the data within it hence it then returns an error stating the rs is closed.

Any ideas why it might be doing this? I am not telling the rs too clsoe anywhere in my code (yet).

Cheers
Adam
Nov 21 '05 #2
Gerry,
You should be using a dataset not a recordset in VB.NET.


The upgrade uses that, so this sounds for me a little bit that you say that
the Microsoft product is not OK, do you want to say that?

Cor
Nov 21 '05 #3
Adam,

This is in my eyes impossible to answer without the part of code you are
talking about.

And forgive me tha I do not know it, however what is an UDL .

Cor
Nov 21 '05 #4
Cor,

A UDL is a Universal DataLink file used to connect to database.

To make one ....
Right click on your desktop and use the context menu shortcut to create a new text file.
rename it as "somefilename.udl".
It will change the file type and the icon (when you change the file extension and save it windows converts the file automatically).
If you then double click to open the new created file it should be self explanatory for filling in sql server etc.

I then use it my code like this example:
#######
Dim udl As String = "FileName=Some:path\to\the\udl\file.udl"
Dm cn As New ADODB.Connection
Dim SQLStatement As String = "Select ColumnA From ThisTable Where ColumnA = 123"

cn.ConnectionString = udl
cn.Open
rs = cn.Execute(SQLStatement)
With rs
If Not (.BOF And .EOF) Then
.MoveFirst()
Do While Not .EOF
MsgBox(.Fields(0).Value)
Loop
End If
End With
cn.Close
##############

I'll try using this with a dataset to see if I get a better result than using recordsets.

Cheers
Adam

Nov 21 '05 #5
Hi Gerry,

Any reason why that is?
The first few queries execute fine using rs to hold the results.

Cheers
Adam

Nov 21 '05 #6
No, not saying that at all Cor.

Saying that the Dataset is so much easier to use and in my opinion, better.

--
Gerry O'Brien [MVP]
Visual Basic .NET(VB.NET)


"Cor Ligthert" <no**********@planet.nl> wrote in message
news:eo****************@TK2MSFTNGP11.phx.gbl...
Gerry,
You should be using a dataset not a recordset in VB.NET.


The upgrade uses that, so this sounds for me a little bit that you say
that
the Microsoft product is not OK, do you want to say that?

Cor

Nov 21 '05 #7
ADO.NET is designed to work in a disconnected environment which moves the responsibility of managing the records over to the client. This works well in an evironment where the data source may be disconnected due to network issues or latency such as across the Internet or a network connection.

Not only that, but simple updates take place in an in-memory representation of the data which eliminates a round trip to the server. You merely do what amounts to a batch update when you are ready to write the changes back to the data source.

As to why your connection is being closed, can you provide more information?

1) Does it occur at random? On the same record? After a certain number of reads?

2) Is the data source local or across the network?

3) Are there any consistencies that you can see that constitute a pattern of some sort?
--
Gerry O'Brien [MVP]
Visual Basic .NET(VB.NET)


"Adam Maltby" <ad***@frfl.co.uk> wrote in message news:Ow****************@tk2msftngp13.phx.gbl...
Hi Gerry,

Any reason why that is?
The first few queries execute fine using rs to hold the results.

Cheers
Adam
Nov 21 '05 #8
Gerry,
No, not saying that at all Cor.

Saying that the Dataset is so much easier to use and in my opinion, better.


I agree that of course, however that "You should" sounded so cruel and so
definitive when I readed it, ADODB can be used in VB.Net, however I will as
well never recommend it..

:-)

Cor
Nov 21 '05 #9
It always occurs after a certain sql statement has been run.
But I don't how this would affect it.
The datasource is a local install of sql.
The only pattern is it always stops after one particular sql statement - but how would a statement force a record closed......... ?

Nov 21 '05 #10
Possibly if the statement is returning 0 records, in which case an rs.EOF or rs.BOF would be true, and cause errors trying to access anything else having to do with the result set.
"Adam Maltby" <ad***@frfl.co.uk> wrote in message news:eM**************@TK2MSFTNGP15.phx.gbl...
It always occurs after a certain sql statement has been run.
But I don't how this would affect it.
The datasource is a local install of sql.
The only pattern is it always stops after one particular sql statement - but how would a statement force a record closed......... ?
Nov 21 '05 #11
Adam,

I tried your code (not using the UDL however making from that a connection
string, that goes very nice when changing it back to txt) however when it
was running your code comes never at to an end. It did when I made this
little change, (It was a while ago I did something with ADO and my advice is
as well when it is posible to go direct to ADONET).

With rs
If Not (.BOF And .EOF) Then
.MoveFirst()
Do While Not .EOF
.MoveNext
Loop
End If
End With
cn.Close

:-)

And thanks for learning me that method I did not know.

Cor
Nov 21 '05 #12
DOH!!!!!!!!!!!!!!!!!!!!!!!!!!!!
So simple and right under my nose!!!!!
Sorry guys for wasting your time - I should have seen that one coming! :)

Thanks
Adam

Nov 21 '05 #13
Hmmm, you're right. My choosing of words sometimes is not best based on the
context. Especially in written communciation where intent is hard to
discern without the facial or vocal expressions.

You certainly can use ADODB and it is my preference to NOT use it, however,
others are still comfortable with it.

--
Gerry O'Brien [MVP]
Visual Basic .NET(VB.NET)


"Cor Ligthert" <no**********@planet.nl> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Gerry,
No, not saying that at all Cor.

Saying that the Dataset is so much easier to use and in my opinion,

better.


I agree that of course, however that "You should" sounded so cruel and so
definitive when I readed it, ADODB can be used in VB.Net, however I will
as
well never recommend it..

:-)

Cor

Nov 21 '05 #14
Apologies for forgetting the ".movenext" - Was a bit silly of me!

Out of prefernce our company prefers apps to be written using UDL's.....
Do you know if UDL's can populate a .net dataset?

Cheers
Adam

Nov 21 '05 #15
Adam,

The link bellow is OleDB and you should use SQLClient.SQLConnection I never
saw a difference exept with the parameters.

http://msdn.microsoft.com/library/de...tringTopic.asp
However this text is in it.

To reference a UDL, add a reference to the UDL to the ConnectionString in
the form "File Name = myfile.udl". If more than one UDL is specified in the
connection string, only the last occurrence is loaded. If you specify a UDL,
and subsequently call the OleDbConnection object to retrieve the
ConnectionString, the ConnectionString contains the reference to the UDL
file, not the contents of the file. Connection strings that contain UDLs are
parsed each time the OleDbConnection is opened. Because this can affect
performance, a ConnectionString that does not reference a UDL is
recommended.

Maybe you can try it,

I saw it when I was busy with your sample.

Cor
Nov 21 '05 #16

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

Similar topics

8
by: dmiller23462 | last post by:
My brain is nuked....Can anybody tell me right off the bat what is wrong with this code? Along with any glaring errors, please let me know the syntax to display a message (Response.Write would be...
3
by: alex_peri | last post by:
Hello All, I am having problems with sorting a recordset by fields in Access. I have a table with three columns called ID, SNo and Time and would like to sort the records by Time. I would like to...
12
by: (Pete Cresswell) | last post by:
Say I've got a RecordSet: ----------------------------------------------------------- Set myRS = CurrentDB.OpenRecordset(SomeSQL, dbOpenDynaset)...
18
by: Darryl Kerkeslager | last post by:
When I open an ADO Recordset, I close it. However, it seems that there may be some difference in this manner of opening a Recordset: Dim rL As ADODB.Recordset Set rL = New ADODB.Recordset ...
3
by: BillCo | last post by:
This worked for a large database (150+ tables): Do While Not rstLinks.EOF Set td = DB.TableDefs(rstLinks!Name) 'Debug.Print rstLinks!Name If InStr(td.Connect, "corpbe.mdb") Then td.Connect =...
6
by: blue875 | last post by:
Hello helper people who are smarter than me: I have a form that needs to submit multiple queries to different tables during one Sub's execution. Some sections are as simple as: 1| With rst 2|...
8
by: LabGeek | last post by:
Do I have to recreate a recordset everytime I want to use it, or can I simply create a recordset on the form open event and access it for the life of the form? I guess my question is really what...
23
by: PW | last post by:
Hi, I'd like to close a recordset and set the database to nothing if a recordset is open if an error has occured. Leaving a recordset open and a database open isn't a good idea, right? ...
6
by: Oko | last post by:
I'm currently developing an MS Access Data Project (.adp) in MS Access 2002. One of the reports within the DB uses data that is Dynamic and cannot be stored on the SQL Server. To resolve this, I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
Oralloy
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,...
0
jinu1996
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
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,...

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.