Handling a unique key Constraint Violation with powershell and SQL -


i'm writing script insert guid sql table. in order stop duplicates, have made table guid column unique.

so need catch violation , ignore if duplicate , continue script. write new guids ignore duplicates.

what best way catch , deal violation?

i've seen few options on site, none work me, fail catch block missing statement block. or other errors.

example of catch block i've been trying

catch(sqlexception ex)  {       sqlexception = ex.innerexception system.data.sqlclient.sqlexception;      if (sqlexception.number == 2601 || sqlexception.number == 2627)     {         errormessage = "cannot insert duplicate values.";     }     else     {         errormessage = "error while saving data.";     } } 

and errors:

at d:\software approval requests\getapprovalrequestsnew2.ps1:15 char:6 + catch (updateexception ex) +      ~ catch block missing statement block. @ d:\software approval requests\getapprovalrequestsnew2.ps1:18 char:32 +     if (innerexception != null && innerexception.number == 2627 ||     innerexceptio ... +                                ~~ token '&&' not valid statement separator in version. @ d:\software approval requests\getapprovalrequestsnew2.ps1:18 char:65 +     if (innerexception != null && innerexception.number == 2627 || innerexceptio ... +                                                                 ~~ token '||' not valid statement separator in version. @ d:\software approval requests\getapprovalrequestsnew2.ps1:23 char:28 + if (innerexception != null && (innerexception.number == 2627 || innerexception.n ... 


Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - IE9 error '$'is not defined -