Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Insert erroneously inserts two records

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2001-04-16 : 13:23:25
Noelle writes "I'm trying to do an insert into a SQL 7 database and get back the unique identity. I'm using the following code:

Set rs1 = Server.CreateObject("ADODB.Recordset")
rs1.Open "tblTime",objConn,1,3,2
rs1.AddNew
rs1("state_id") = state_id
...
rs1.Update
id = rs1("id")
rs1.Close
Set rs1 = Nothing
objConn.Close

objConn comes from an include file w/ the following code:
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open "dsn=xxx;UID=xxx;pwd=xxx"

I then use the id returned above in serveral insert statements in other tables. The problem is, usually two records are inserted. This is causing my whole application to blow up. The subsequent inserts are only run for the second record. This code is not in a loop, and not being refreshed. I've been over it and over it and I can't find any reason why two records would be inserted. Occasionally, it works correctly and only inserts one record. Then, without making any changes to the code, it will start inserting two again. Why is this happening and how can I reliably get the id back from an insert into SQL 7?"
   

- Advertisement -