By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,044 Members | 1,287 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,044 IT Pros & Developers. It's quick & easy.

opening/maintaincing connections

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.