2

The error that I am getting is:

Error Number: 23000/544

[Microsoft][SQL Server Native Client 11.0][SQL Server]Cannot insert explicit value for identity column in table 'audit_domain' when IDENTITY_INSERT is set to OFF.

UPDATE "domain" SET "domain_acronym" = 'RM', "domain" = Resource Management', "reference_name" = 'Resource Mgmt' WHERE "id" = '1'

The code that I am using:

$updatedata['domain_acronym'] = $this->postdata['domain_acronym'];
$updatedata['domain_name'] = $this->postdata['domain_name'];
$updatedata['reference_name'] = $this->postdata['reference_name'];

$this->db->where($pk, $pkValue);
$this->db->update('domains', $updatedata);

The domain table has the primary key of Id and the audit table doesn't have any primary key set. I have been trying to fix this for a couple of days now so any pointers on how to debug/fix it would be really appreciated.

ajreal
  • 46,720
  • 11
  • 89
  • 119
bidhan
  • 70
  • 9
  • Check this, https://stackoverflow.com/questions/1334012/cannot-insert-explicit-value-for-identity-column-in-table-table-when-identity?rq=1 – Naga Jun 19 '17 at 01:47
  • Possible duplicate of [Cannot insert explicit value for identity column in table 'table' when IDENTITY\_INSERT is set to OFF](https://stackoverflow.com/questions/1334012/cannot-insert-explicit-value-for-identity-column-in-table-table-when-identity) – Ganesh Jun 19 '17 at 03:10

2 Answers2

0

Run this query

SET IDENTITY_INSERT YourtableName ON
Ganesh
  • 3,128
  • 2
  • 17
  • 27
  • it works when i run the SQL from sql manager. Its $this->db->update('domains', $updatedata) where it fails – bidhan Jun 19 '17 at 03:17
0

Try in this way

$domain_acronym = $this->postdata['domain_acronym'];
$domain_name = $this->postdata['domain_name'];
$reference_name = $this->postdata['reference_name'];

$query="update table_name set col_name1='$domain_acronym',col_name2='$domain_name ',col_name3='$reference_name ' where id=$pkValue";

$this-db->query($query);
  • A note: this advice is prone to SQL Injection vulnerability. – zerkms Jun 19 '17 at 04:34
  • codeigniter provide Cross-site request forgery (CSRF) Security Class so we use this class for Security – Support Techcherry Jun 19 '17 at 04:41
  • 1. It's not me asked a question but someone else. I just made a comment. 2. CSRF has nothing to do with sql injections 3. People tend to copy paste from stackoverflow. So if an answer contains a security vulnerability be sure it also will be ported to their code. – zerkms Jun 19 '17 at 04:44