# getKey from SQL Server

**URL:** <https://forum.inductiveautomation.com/t/getkey-from-sql-server/11091>\
**Category:** Ignition\
**Created:** [January 21, 2016, 10:07pm UTC](https://forum.inductiveautomation.com/t/getkey-from-sql-server/11091 "2016-01-21T22:07:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![boandersen](https://avatars.discourse-cdn.com/v4/letter/b/13edae/32.png) [@boandersen](https://forum.inductiveautomation.com/u/boandersen)\
**Post date:** [January 21, 2016, 10:07pm UTC](https://forum.inductiveautomation.com/t/getkey-from-sql-server/11091/1 "2016-01-21T22:07:17Z")

</div>

I am kind of confused about this because this worked yesterday and I have no clue what changed… On SQL Server 2014, Ignition 7.8 on Java 8.65

I cannot retrieve the key from an insert using getKey:

Here is a simplified example that fails

A) SQL  
create table temp (id int identity (1,1)not null, name varchar(110) null)

ALTER TABLE [temp] ADD CONSTRAINT [PK\_temp] PRIMARY KEY CLUSTERED  
(  
[id] ASC  
)

B) Button on window  
qry = “INSERT INTO TEMP (name) Values (?)”  
v = “I was here”  
ts = system.db.runPrepUpdate(qry, [v], getKey=1)  
print ts

C) result

Traceback (most recent call last):  
File “event:actionPerformed”, line 3, in

java.lang.Exception: java.lang.Exception: Error executing system.db.runPrepUpdate(INSERT INTO TEMP (name) Values (?), [I was here], , true, false)

```
caused by Exception: Error executing system.db.runPrepUpdate(INSERT INTO TEMP (name) Values (?), [I was here], , true, false)
caused by GatewayException: SQL error for "INSERT INTO TEMP (name) Values (?)": A result set was generated for update.
caused by SQLServerException: [b]A result set was generated for update. 

```

[/b]

The INSERT succeeds but the key is not returned and the code errors out

Ideas welcome

Thanks

---

<div class="post-metadata">

**Author:** ![boandersen](https://avatars.discourse-cdn.com/v4/letter/b/13edae/32.png) [@boandersen](https://forum.inductiveautomation.com/u/boandersen)\
**Post date:** [January 21, 2016, 10:39pm UTC](https://forum.inductiveautomation.com/t/getkey-from-sql-server/11091/2 "2016-01-21T22:39:48Z")

</div>

This solved itself sort of… Java on the server had tried to update and had deleted some files in the 8.0.65 folder.

I allowed it to finish and the problem disappered.

I’m leaving the topic in case it can help others.

---

<div class="post-metadata">

**Author:** ![boandersen](https://avatars.discourse-cdn.com/v4/letter/b/13edae/32.png) [@boandersen](https://forum.inductiveautomation.com/u/boandersen)\
**Post date:** [January 22, 2016, 5:09pm UTC](https://forum.inductiveautomation.com/t/getkey-from-sql-server/11091/3 "2016-01-22T17:09:04Z")

</div>

Behavior is back… Has anyone else seen this? Have restarted gateway and no Java update this time

---

<div class="post-metadata">

**Author:** ![MMaynard](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mmaynard/32/3366_2.png) [@MMaynard](https://forum.inductiveautomation.com/u/MMaynard)\
**Post date:** [January 23, 2016, 7:31pm UTC](https://forum.inductiveautomation.com/t/getkey-from-sql-server/11091/4 "2016-01-23T19:31:59Z")

</div>

From everything I can see it looks like a JDBC driver bug.  
Have you tried formatting it as a runUpdateQuery?

---

<div class="post-metadata">

**Author:** ![boandersen](https://avatars.discourse-cdn.com/v4/letter/b/13edae/32.png) [@boandersen](https://forum.inductiveautomation.com/u/boandersen)\
**Post date:** [January 25, 2016, 1:38pm UTC](https://forum.inductiveautomation.com/t/getkey-from-sql-server/11091/5 "2016-01-25T13:38:56Z")

</div>

I’ve not tried as a runUpdateQuery - I changed it to a stored procedure instead.
