Is this Proper?

Is this Proper?

am 03.05.2005 20:02:49 von Ron Smith

--0-1115803254-1115143369=:82003
Content-Type: text/plain; charset=us-ascii

This question may have been addressed before, but I'm still unclear as to what's happening under the hood. I normally use ASP pages to access an MS Access database, but I'd like to switch over to using ASP pages with MySQL.

Usually I use the following code to insert a record and then close the table and connection with Access:

objRS.AddNew
objRS("Name") = name
objRS("Address") = address
objRS("City") = city
objRS("State") = state
objRS("Zip") = zip
objRS("Phone") = phone
objRS.Update

objRS.close
set objRS="nothing"
objConn.close
set objConn="nothing"

With MySQL, I use the following instead:

sql="insert into friends_contact_info.friends (Name, StreetAddress, City, State, ZipCode, PhoneNumber) values ('"&name&"', '"&address&"', '"&city&"', '"&state&"', '"&zip&"', '"&phone&"')"
set objRS=objConn.execute(sql)

I comment out the following lines when I'm adding records to MySQL tables. At first, I was just commenting out the first two lines, but I would get an error message. The record added to the table would be fine, but I'd get an error. So, I decided to comment out everything to elliminate the error messages. Is this proper or am I leaving the table and connection open? Is there a test for this, after the the 'insert into' statement?

'objRS.close
' set objRS="nothing"
'objConn.close
' set objConn="nothing"

--0-1115803254-1115143369=:82003--

RE: Is this Proper?

am 03.05.2005 20:27:48 von ml.mysql

> =20
> 'objRS.close
> ' set objRS=3D"nothing"
> 'objConn.close
> ' set objConn=3D"nothing"


Set object =3D Nothing (no quotes)

set objRS =3D Nothing

Always set objects to nothing when you are done with them.

-Kevin

--
MySQL Windows Mailing List
For list archives: http://lists.mysql.com/win32
To unsubscribe: http://lists.mysql.com/win32?unsub=3Dgcdmw-win32@m.gmane.org

Re: Is this Proper?

am 03.05.2005 20:39:04 von Daniel da Veiga

Without knowing the error message it is difficult for us to help,
could you post the exact error you get? What kind of tables are you
using? And what is the MySQL server version? Is is running on a
Windows platform? Are you using ASP.Net?

If you comment that lines you'll get warnings cause MySQL will
forcelly close all open connections iddle for more than the
wait_timeout and interactive_timeout variables, besides, your objects
will not free the memory used, that can be dangerous after some time
and maybe cause unexpected behavior.


On 5/3/05, PF: MySQL wrote:
> >
> > 'objRS.close
> > ' set objRS=3D"nothing"
> > 'objConn.close
> > ' set objConn=3D"nothing"
>=20
> Set object =3D Nothing (no quotes)
>=20
> set objRS =3D Nothing
>=20
> Always set objects to nothing when you are done with them.
>=20
> -Kevin
>=20
> --
> MySQL Windows Mailing List
> For list archives: http://lists.mysql.com/win32
> To unsubscribe: http://lists.mysql.com/win32?unsub=3Ddanieldaveiga@gma=
il.com
>=20
>=20


--=20
Daniel da Veiga
Computer Operator - RS - Brazil

--
MySQL Windows Mailing List
For list archives: http://lists.mysql.com/win32
To unsubscribe: http://lists.mysql.com/win32?unsub=3Dgcdmw-win32@m.gmane.org

RE: Is this Proper?

am 04.05.2005 02:17:15 von jbonnett

I think the reason you were getting an error when you closed the
recordset object is that it was not really open. Since you have executed
an action query (insert), no recordset is returned.

You should probably write just

objConn.Execute(sql)

and forget about the recordset.

You know exactly the same code should work for Access too. A recordset
is not really needed in either case.

Whether you should close and destroy the connection object is another
issue. In an ASP application you probably should. It's really a matter
of balancing the work it takes to set up the connection when you need it
again against the resources that are tied up while the connection is
left open.

John Bonnett

-----Original Message-----
From: Ron Smith [mailto:geeksatlarge@yahoo.com]=20
Sent: Wednesday, 4 May 2005 3:33 AM
To: MySQL Mailing List
Subject: Is this Proper?

This question may have been addressed before, but I'm still unclear as
to what's happening under the hood. I normally use ASP pages to access
an MS Access database, but I'd like to switch over to using ASP pages
with MySQL.
=20
Usually I use the following code to insert a record and then close the
table and connection with Access:
=20
objRS.AddNew
objRS("Name") =3D name
objRS("Address") =3D address
objRS("City") =3D city
objRS("State") =3D state
objRS("Zip") =3D zip
objRS("Phone") =3D phone
objRS.Update
=20
objRS.close
set objRS=3D"nothing"
objConn.close
set objConn=3D"nothing"
=20
With MySQL, I use the following instead:
=20
sql=3D"insert into friends_contact_info.friends (Name, StreetAddress,
City, State, ZipCode, PhoneNumber) values ('"&name&"', '"&address&"',
'"&city&"', '"&state&"', '"&zip&"', '"&phone&"')"
set objRS=3DobjConn.execute(sql)
=20
I comment out the following lines when I'm adding records to MySQL
tables. At first, I was just commenting out the first two lines, but I
would get an error message. The record added to the table would be fine,
but I'd get an error. So, I decided to comment out everything to
elliminate the error messages. Is this proper or am I leaving the table
and connection open? Is there a test for this, after the the 'insert
into' statement?
=20
'objRS.close
' set objRS=3D"nothing"
'objConn.close
' set objConn=3D"nothing"

--
MySQL Windows Mailing List
For list archives: http://lists.mysql.com/win32
To unsubscribe: http://lists.mysql.com/win32?unsub=3Dgcdmw-win32@m.gmane.org

RE: Is this proper?

am 04.05.2005 02:39:42 von ml.mysql

> =20
> set objRS=3DobjConn.execute(sql)
> =20
> objRS.close <===========3D Line 61
> set objRS=3Dnothing
> objConn.close
> set objConn=3Dnothing
> =20
> The record goes in OK, but, it seems I can't avoid the error=20
> unless *all* four lines are commented out.


If you are just inserting a record, you don't really need to have a
recordset object at all...

Just do something like this:

objConn.Execute "INSERT INTO ...blah...blah..."


-Kevin

--
MySQL Windows Mailing List
For list archives: http://lists.mysql.com/win32
To unsubscribe: http://lists.mysql.com/win32?unsub=3Dgcdmw-win32@m.gmane.org

RE: Is this Proper?

am 04.05.2005 19:29:30 von Ron Smith

--0-413060060-1115227770=:3812
Content-Type: text/plain; charset=us-ascii

Yes,

I removed all lines referring to the recordset; kept the line closing the connection, then the insertion of records worked fine, with *no* errors.

Thanks, to you and everyone on the list that pitched in.

Ron

jbonnett@sola.com.au wrote:
I think the reason you were getting an error when you closed the
recordset object is that it was not really open. Since you have executed
an action query (insert), no recordset is returned.

You should probably write just

objConn.Execute(sql)

and forget about the recordset.

You know exactly the same code should work for Access too. A recordset
is not really needed in either case.

Whether you should close and destroy the connection object is another
issue. In an ASP application you probably should. It's really a matter
of balancing the work it takes to set up the connection when you need it
again against the resources that are tied up while the connection is
left open.

John Bonnett

-----Original Message-----
From: Ron Smith [mailto:geeksatlarge@yahoo.com]
Sent: Wednesday, 4 May 2005 3:33 AM
To: MySQL Mailing List
Subject: Is this Proper?

This question may have been addressed before, but I'm still unclear as
to what's happening under the hood. I normally use ASP pages to access
an MS Access database, but I'd like to switch over to using ASP pages
with MySQL.

Usually I use the following code to insert a record and then close the
table and connection with Access:

objRS.AddNew
objRS("Name") = name
objRS("Address") = address
objRS("City") = city
objRS("State") = state
objRS("Zip") = zip
objRS("Phone") = phone
objRS.Update

objRS.close
set objRS="nothing"
objConn.close
set objConn="nothing"

With MySQL, I use the following instead:

sql="insert into friends_contact_info.friends (Name, StreetAddress,
City, State, ZipCode, PhoneNumber) values ('"&name&"', '"&address&"',
'"&city&"', '"&state&"', '"&zip&"', '"&phone&"')"
set objRS=objConn.execute(sql)

I comment out the following lines when I'm adding records to MySQL
tables. At first, I was just commenting out the first two lines, but I
would get an error message. The record added to the table would be fine,
but I'd get an error. So, I decided to comment out everything to
elliminate the error messages. Is this proper or am I leaving the table
and connection open? Is there a test for this, after the the 'insert
into' statement?

'objRS.close
' set objRS="nothing"
'objConn.close
' set objConn="nothing"

--
MySQL Windows Mailing List
For list archives: http://lists.mysql.com/win32
To unsubscribe: http://lists.mysql.com/win32?unsub=geeksatlarge@yahoo.com


--0-413060060-1115227770=:3812--