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

opening/maintaincing connections

I have a ASPX page which needs to make several writes to a database,
using data from a form. I am using an MS Access db.

Currently, I am managing my connections/writes as follows..

myConnection = New OleDBConnection(connectionString)
myConnection.Open()

sql = "first sql statment"
myCommand = New OleDbCommand(sql, myConnection)
myReader = myCommand.ExecuteReader()
myReader.Close()

sql = "2nd sql stmt"
myCommand = New OleDbCommand(sql, myConnection)
myReader = myCommand.ExecuteReader()
myReader.Close()

sql = "3rd sql stmt"
myCommand = New OleDbCommand(sql, myConnection)
myReader = myCommand.ExecuteReader()
myReader.Close()

etc etc.. Is this the optimal way of doing writes to database? The
repeated creation of teh command object seems "not so right" to me..

Thoughts?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #1
2 1521
You should be worried about the use of an unused DataReader before you worry
about using the necessary Command object! Try using ExecuteNonQuery instead,
and remember that just because a function returns a value doesn't mean you
have to assign that value to anything.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"Bijoy Naick" <b_*****@donoteamil.yahoo.ca> wrote in message
news:#y**************@TK2MSFTNGP11.phx.gbl...
I have a ASPX page which needs to make several writes to a database,
using data from a form. I am using an MS Access db.

Currently, I am managing my connections/writes as follows..

myConnection = New OleDBConnection(connectionString)
myConnection.Open()

sql = "first sql statment"
myCommand = New OleDbCommand(sql, myConnection)
myReader = myCommand.ExecuteReader()
myReader.Close()

sql = "2nd sql stmt"
myCommand = New OleDbCommand(sql, myConnection)
myReader = myCommand.ExecuteReader()
myReader.Close()

sql = "3rd sql stmt"
myCommand = New OleDbCommand(sql, myConnection)
myReader = myCommand.ExecuteReader()
myReader.Close()

etc etc.. Is this the optimal way of doing writes to database? The
repeated creation of teh command object seems "not so right" to me..

Thoughts?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 18 '05 #2
CT
Well, this is what disconnected data access is all about. Obviously, it's
more time consuming to create, open, and subsequently close a connection for
every request, but your alternative is to save the (open) connection in the
Session object, which is resource consuming. I'm not getting drawn into a
discussion of what's the best appraoch at this time; it's the job at hand
that should decide this. However, from what little I can see from your code,
your approach looks okay. Performing some tests with different approaches
might give you a different answer though.

--
Carsten Thomsen
Enterprise Development with VS .NET, UML, and MSF
http://www.apress.com/book/bookDisplay.html?bID=105
"Bijoy Naick" <b_*****@donoteamil.yahoo.ca> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
I have a ASPX page which needs to make several writes to a database,
using data from a form. I am using an MS Access db.

Currently, I am managing my connections/writes as follows..

myConnection = New OleDBConnection(connectionString)
myConnection.Open()

sql = "first sql statment"
myCommand = New OleDbCommand(sql, myConnection)
myReader = myCommand.ExecuteReader()
myReader.Close()

sql = "2nd sql stmt"
myCommand = New OleDbCommand(sql, myConnection)
myReader = myCommand.ExecuteReader()
myReader.Close()

sql = "3rd sql stmt"
myCommand = New OleDbCommand(sql, myConnection)
myReader = myCommand.ExecuteReader()
myReader.Close()

etc etc.. Is this the optimal way of doing writes to database? The
repeated creation of teh command object seems "not so right" to me..

Thoughts?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 18 '05 #3

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

Similar topics

3
by: Usman | last post by:
Hi All, Is there a way that if I know the IP address of a computer, I can open a popup window on that IP remotely from another computer? It is somewhat similar to netsend but the type of window...
5
by: Daves | last post by:
is it a good or bad practise to use the session_start & session_end for opening & closing the database connection? I'd thought that on powerful servers today the time the connection is kept locked...
3
by: Parveen | last post by:
Is it possible to use a data reader to retrieve data from a database while another connection is currently open? I want to access the same database but I need to retrieve data from one table based...
1
by: Christopher | last post by:
I have a question about Sql. When I run a simple open statement for a SQL database, it opens up two connections sometimes, and other times it opens up one connection. Does anyone know why this...
4
by: arbpen | last post by:
I am concerned about performance. Usually, in a situation where I am not using a global.asa (shared host, etc), I explicitly close the connection at the bottom of the page in a footer, eg:...
7
by: Martien van Wanrooij | last post by:
I have been faced a couple of times with the situation that I wanted to write a script and was worried about a too frequent opening and closing mysql connections. To give some examples: 1)I...
15
by: Umesh | last post by:
how to open a website like yahoo.com and use it as input? The following code doesn't work. #include"stdio.h" int main() { FILE *f; f=fopen("http://www.yahoo.com","r"); if(f==NULL)
2
by: Stephen2 | last post by:
I've written a small dos batch script that runs a simple query through osql and then calls an exe which sends an email if the returned value The query checks if a value in a column has not been...
4
by: kessa | last post by:
Hi Guys, I've recently had a problem with my site displaying a "system resources exceeded" error message ... and whilst searching this site for a solution (which I think I've now found) I came...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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.