Detect Current IDENTITY_INSERT Settings?

Is there any way to programmatically detect the current value(s) of the IDENTITY_INSERT property, specifically (a) whether it's ON or OFF, and/or (b) if it's ON which table it's on for?
I have a table with an INSTEAD OF INSERT trigger which does a data check prior to insertion.  The table has existing data.  I'm trying to add the IDENTITY property to one of the columns in the PK so that going forward, the PK value is automatically generated on new rows.  Unfortunately, the INSERT in the trigger only works if IDENTITY_INSERT is off.  If IDENTITY_INSERT myTable is ON, the INSERT statement in the trigger fails because the identiy column is not coded in it.
I tried putting the INSERT in a TRY...CATCH block, testing for error 545 in the CATCH and issuing a second INSERT with the PK column coded in it, but once you hit the CATCH block in a trigger SQL Server deems the entire transaction as "failed", and you can only roll it back (error 3930).
CREATE TRIGGER myTable_tIiof
ON myTable INSTEAD OF INSERT
AS
BEGIN
 SET NOCOUNT ON;
 IF (EXISTS (SELECT TOP 1 i1.col2 FROM inserted i1
  WHERE (EXISTS (SELECT TOP 1 r1.col1
    FROM myTable r1
    WHERE i1.col2= r1.col2
    AND UPPER(i1.col3) = UPPER(r1.col3)) ))) BEGIN
    PRINT 'INSERT failed - violation of duplicate col2 and col3 restriction';
 END ELSE
 BEGIN TRY
   INSERT INTO myTable (col2, col3, col4)
   SELECT i.col2, i.col3, i.col4 FROM inserted i
 END TRY
 BEGIN CATCH
   IF ERROR_NUMBER() = 545 BEGIN    -- IDENTITY_INSERT is on:
     BEGIN TRY
      INSERT INTO myTable (col1, col2, col3, col4)
      SELECT i.col1, i.col2, i.col3, i.col4 FROM inserted i
     END TRY
     BEGIN CATCH  -- Some other error occurred after second INSERT attempt:
      SELECT ERROR_NUMBER() AS ErrorNumber;
      IF @@TRANCOUNT > 0 ROLLBACK;
     END CATCH
   END ELSE BEGIN --
     SELECT ERROR_NUMBER() AS ErrorNumber;
     IF @@TRANCOUNT > 0 ROLLBACK;
   END
 END CATCH
END
IDEALLY, I want to do the following:
CREATE TRIGGER myTable_tIiof
ON myTable INSTEAD OF INSERT
AS
BEGIN
 SET NOCOUNT ON;
 IF (EXISTS (SELECT TOP 1 i1.col2 FROM inserted i1
  WHERE (EXISTS (SELECT TOP 1 r1.col1
    FROM myTable r1
    WHERE i1.col2= r1.col2
    AND UPPER(i1.col3) = UPPER(r1.col3)) ))) BEGIN
    PRINT 'INSERT failed - violation of duplicate col2 and col3 restriction';
 END ELSE BEGIN
   IF MissingFunction1(IsIdentityInsertOn) = true AND MissingFunction2(IdentityInsertObject) = 'myTable' BEGIN
      INSERT INTO myTable (col1, col2, col3, col4)
      SELECT i.col1, i.col2, i.col3, i.col4 FROM inserted i
   END ELSE BEGIN
     INSERT INTO myTable (col2, col3, col4)
     SELECT i.col2, i.col3, i.col4 FROM inserted i
   END
END
Do MissingFunction1 and/or MissingFunction2 exist?  If so, what are they called?
(And if they don't exist, why don't they exist?)
Thanks in advance... Bryan

I figured out a solution to this problem in the case where you are trying to re-insert an old record into a table (insert an ID that is lower than would be inserted normally).  I put the following code around the part of the trigger that won't work
with IDENTITY_INSERT set on (in my case a part of the trigger that inserts related records into the same table)
if
(select
max(id)
from
MyTable) <
(select
max(id)
from inserted)
--Then you may be inserting a record normally
BEGIN
    set @I
= 1
--SQL wants something to happen in the "IF" side of an IF/ELSE
END
ELSE --You definitely have IDENTITY_INSERT on.  Done as ELSE instead of the other way around so that if there is no inserted table, it will run anyway
BEGIN
.... Code that shouldn't run with IDENTITY_INSERT on
END

Similar Messages

  • One or more ActiveX controls could not be displayed because either:1 your current security settings prohibit running ActiveX controls on this page, or 2. You have blocked a publisher of one of the controls.

    hi All,
    i have one of the requirement for an application, we do upload some release not in file server and that is used in application link to see the note. in this note i have converted the Excel into .HTM format(web page). this was working fine, but from last
    two days all of a sudden we are recieving error as above.
    one or more ActiveX controls could not be displayed because either:1 your current security settings prohibit running ActiveX controls on this page, or 2. You have blocked a publisher of one of the controls.
    could anyone please help me on this.
    Thanks and Regards,
    krishnamurthy

    Hi,
    Actually Arnavsharma provided a operable method for you. But no luck, it's not invalid.
    Here I also offer you an method you can try.Please delete the extra (parasite) zone from the Zones subkey :
    Click Start , click Run , type regedit , and then click OK
    Expand the following registry subkey
    HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones
    Delete the extra (parasite) zone from the Zones subkey
    Note: The parasite zone is a pseudo-graphic number listed before zone number 0. The pseudo-graphic number looks like a miniature upper case "L"
    Close the registry editor
    Thanks!
    We
    are trying to better understand customer views on social support experience, so your participation in this
    interview project would be greatly appreciated if you have time.
    Thanks for helping make community forums a great place.

  • "current encoder settings for bit rate and sample rate are invalid" message

    I have some files I am working with. Details and what happened:
    Had some music files where I was doing some trimming/splitting. Files worked fine in itunes.
    Open the files in Quicktime Pro 7 to trim them. Exported to aif.
    Opened the files with itunes. They open and play just fine.
    In Itunes I click"create AAC version" to convert them.
    I receive the message "An error occurred while trying to import the file. The current encoder settings for bit rate and sample rate are not valid for this file."
    I don't know what to do from here. Suggestions?
    Thanks.

    Make sure that the AIFFs that you export are set for 16 bit PCM.
    Also, assuming that you are using 44.1 kHZ sampling in your AIFFs, make sure that you are not trying to use 48 kHz in the AAC.

  • Your current security settings do not allow this file....

    Trying to download the latest version of iTunes and get the message "Your current security settings do not allow this file to be downloaded." I have made no changes at all, previous to attempting to download this update and have never had a download problem previous to this. I turned off my antivirus and set my browser security to its' lowest security level; still get the same message.

    Uh...that would be a tad difficult. I'm not supposed to have it. No one is...yet. I keep in touch with a friend I worked with as a PC tech about 10 years ago at a Best Buy (while in college.) He does Beta testing, sends me odds and ends (that typically wreck my system) and this one halfway works (actually less than half the features.) But, I've escaped bad software in the past using it. Sometimes, however, it prevents good software from loading as well. That's why I have asked if anyone else reported this kind of thing.
    The name, if you can find it, is 'Illegal Opcodes Anti-Trash.' Illegal Opcode is a screen name, by the way. And, it was written using Visual Basic. That's about all I can give you; that's pretty much all I know.
    If anyone else can verify something similar to this, let me know. I could uninstall it (Anti-Trash) and try again, but I just read other peoples problems and I'm a little leary to say the least. My current version of iTunes still works fine, so why risk it.
    Thanks for the feedback,
    Bradley

  • Print only the external movie with its current applied settings?

    Hi,
    I'm making a flash application for a paint company to test various paints on different objects. But I got a little problem.
    Which is here...
    Here is my code....
    /* Print Button Function Here.....*/
    print_btn.addEventListener(MouseEvent.CLICK,printPage);
    function printPage(evt:MouseEvent) {
        var printJob:PrintJob = new PrintJob();
        if (printJob.start()) {
            if (uiLoader.source.width>printJob.pageWidth) {
                uiLoader.source.width=printJob.pageWidth;
                uiLoader.source.scaleY=uiLoader.source.scaleX;
            printJob.addPage(Sprite(uiLoader.source));  
            printJob.send();
    Actually I have a movie clip which contains a Print Button and a uiloader.
    uiloader loads differnt external movies.
    I applied a code to Print button to print those movies.
    This code is working good but problem is, it print the both (main_movie & external_movie) with its actual colors not with the current applied colors.
    I want to print only External movie with its current color settings (applied by user) not actual default colors.
    So can any one tell me how can i do this?
    Thank for help....

    use:
    print_btn.addEventListener(MouseEvent.CLICK,printPage);
    function printPage(evt:MouseEvent) {
        var printJob:PrintJob = new PrintJob();
        if (printJob.start()) {
            if (uiLoader.width>printJob.pageWidth) {
                uiLoader.width=printJob.pageWidth;
                uiLoader.scaleY=uiLoader.scaleX;
            printJob.addPage(uiLoader);  
            printJob.send();

  • Unable to display Info path form using IE , The form cannot be displayed in the browser because the use of DOM storage has been disabled in the current browser settings. In order to load the form, DOM storage must be allowed.

    I have edited the default edit form for my Issue Tracking Tool using Info Path, But currently when I try accessing the form using IE 10 64x , I got the following error-
    “The form cannot be displayed in the browser because the use of DOM storage has been disabled in the current browser settings. In order to load the form, DOM storage must be allowed.”
    But using Firefox I was able to access the edit form , so can anyone advice on this please?
    Thanks

    . Tools > Internet Options > Privacy Tab > Advanced
    Check the over-ride box to Enable/Accept cookies. Click on Always allow session
    cookies.
    2. Clear Your Cache and Cookie Files
    If you are using an Internet Explorer browser, please follow these instructions to clear
    your cache and cookie files: Open your Internet Explorer browser.
    Tools > Internet Options > General > Browsing History
    Click Delete Browsing History.
    Delete Temporary Internet Files, Cookies and History Also under Browsing History,
    click Settings and make sure that your browser automatically checks for newer versions
    of stored pages. Click OK and restart your browser
     3. Pop-up Blockers
    Turn Off the firewall in IE.
    you can disable\enable it from below:
    http://webdevwonders.com/clear-dom-storage/
    Clear DOM Storage in Firefox:
    Select “Tools” -> “Clear Recent History”, open “Details”, check “Cookies” and select “Everything” as time range.
    ATTENTION: No other time range will clear the DOM Storage. Have a look at
    Mozillas documentation for further info.
    Disable DOM Storage in Firefox:
    Type “about:config” in your address bar and hit enter to view your internal browser settings. Scroll down to „dom.storage.enabled“, right click on it and hit „Toggle“ to disable the DOM Storage.
    Clear DOM Storage in Internet Explorer:
    Select “Tools” -> “Internet Options” -> “General” -> check “Delete browsing history on exit”, click on “Delete”, check “Cookies”, click on “Delete” once more and restart your browser afterwards.
    Disable DOM Storage in Internet Explorer:
    Select “Extras” -> “Internet Options” -> “Advanced” Tab -> Go to “Security” -> uncheck “Enable DOM-Storage”
    Clear DOM Storage in Chrome:
    Select “Tools” -> “Clear browsing data…”, check “Delete cookies and other site data”, select “Everything” from “Clear data from this period” and click on “Clear browsing data”.
    Disable DOM Storage in Chrome:
    Open “Options” and select “Under the Hood” Tab. Click on “Content settings…”, select “Cookies” and set “Block sites from setting any data”.
    If this helped you resolve your issue, please mark it Answered
    ok i did all these steps but still i am getting the same error,, i can not understand how SharePoint works better on firefox and chrome comparing to IE !!! so what i should do now , as all the edit forms that are customized using Info path can not be viewed
    on IE 10 64x !!!!

  • Will i lose my current app settings if i upgrade my ios?

    Will I lose my current app settings if I upgrade my iOS from 3.0.1 to 4.3.3?  Such as, will I lose my contacts, email settings and all my levels in Angry Birds (and other obviously very important items like that)?

    Don't know why you would.
    You should be syncing all of this with your computer regularly, so everything (contacts/calendars/etc) should be on your computer anyway.  When you sync your iphone itunes performs a backup which would contain the app data and settings.

  • Why doese this message appear"Your current security settings don't allow this file to be downloaded"

    no one helped me in this post, why Adobe Company doesn't have an answer to my question?
    please, i need your help
    "Dear Helpers,
    We used to use adobe reader 6 in our foundation to view pdf files on the internet, and since we had upgraded to the new version of adobe (to adobe 7 and X) the browser (IE 8) couldn't open any pdf file, and always returning this message: "Your current security settings do not allow this file to be downloaded".
    we have a group policy that doesn't allow the users to download files from the internet, but when we were using adobe reader 6, this message have not occurred while opening pdf file online, and everything was fine,"
    Please help me in this issue
    Thanks in advance
    Kind regards

    Hi eleanora27327971,
    I don't think there's a problem with the PDF file that you converted--that sounds more like a browser setting. What browser are you using? Are you able to download files from other websites? Or, are you able to log in to https://cloud.acrobat.com using a different web browser, and download from that browser? (See System requirements | Acrobat.com for a list of supported web browsers.)
    Tell me a bit more about your setup (what operating system, browser and version), and I should be able to point you in the right direction.
    Best,
    Sara

  • My fire fox download helper not detected current video on you tube. It's always shows only the first video which i was downloaded.pls help

    My fire fox download helper not detected current video on you tube. It's always shows only the first video which i was downloaded.pls help

    You need to refresh the page (F5) to update the items in the download menu. Apparently YouTube refreshes the page in such a way that the extension doesn't gets notified, so you need to refresh the page manually if you want to download a media file from this page.

  • Cannot find a token authenticator for the 'System.IdentityModel.Tokens.X509SecurityToken' token type. Tokens of that type cannot be accepted according to current security settings.

    i am using a custom binding in the BTS Adapter with the following elements (similar to TransportWithMessageCredential with both the client and the server certs)
     encoding (soap11)
     https transport
    Security : CertificateOverTransport
    Problem: the request is sent successfully, but when i receive the response in BizTalk i get the following error
    System.ServiceModel.Security.MessageSecurityException: An unsecured or incorrectly secured fault was received from the other party. ,after turning on tracing in the WCF Trace the following error is present "Tokens of that type
    cannot be accepted according to current security settings. "
    Solutions tried
    1) Changed the security to MutualCertificate , this time request also fails with the following error message  The remote endpoint did not provide a domain name system (DNS) claim and therefore did not satisfied DNS identity 'xxxx.com'.
    This may be caused by lack of DNS or CN name in the remote endpoint X.509 certificate's distinguished name.
    Binding configuration
     <behaviors>
          <endpointBehaviors>
            <behavior name="EndpointBehavior">
              <clientCredentials>
                <clientCertificate findValue="XXXXXXXXXXXXXXX" x509FindType="FindByThumbprint" />
                <serviceCertificate>
                  <defaultCertificate findValue="XXXXXXXXXXXX" storeName="TrustedPeople" x509FindType="FindByThumbprint" />
                  <authentication certificateValidationMode="None" revocationMode="NoCheck" />
                </serviceCertificate>
              </clientCredentials>
            </behavior>
          </endpointBehaviors>
          <serviceBehaviors>
            <behavior name="ServiceBehavior" />
          </serviceBehaviors>
        </behaviors>
        <bindings>
          <customBinding>
            <clear />
            <binding name="XXXXXXXXX">
              <textMessageEncoding messageVersion="Soap11" />
              <security allowSerializedSigningTokenOnReply="true" authenticationMode="CertificateOverTransport" requireDerivedKeys="false" securityHeaderLayout="Lax" messageSecurityVersion="WSSecurity10WSTrust13WSSecureConversation13WSSecurityPolicy12BasicSecurityProfile10"
    requireSecurityContextCancellation="false">
                <secureConversationBootstrap />
              </security>
              <httpsTransport />
            </binding>
          </customBinding>
        </bindings>
    Thanks -Madhu

    Please refer to the similar discussion:
    http://social.msdn.microsoft.com/Forums/en-US/6a3d38ee-30ca-43fb-b906-6e95808df69d/cannot-find-a-token-authenticator-for-the-systemidentitymodeltokensx509securitytoken-token?forum=wcf

  • How to disable security warning "Your current security settings put your computer at risk"

    Hi,
    I wonder if able to disable the security warning bar at the bottom of the IE window.  I enabled the ActiveX control and plug-ins in the IE Option settings, this caused the  security warning "Your current security settings put
    your computer at risk" pop up whenever load the pages.  Is there a way can turn off this warning?
    Thanks a lot for helping!

    That is not an option for Koreans...
    In Korea, most of commercial, financial, or governmental operations need to be done on the Internet. In early 2000's, IE could not support high security outside US due to US laws (that was stupid, but happened) , so Korean sites developed cryptography ActiveX
    controls to circumvent it. Korean government made laws to force all sites to use those kind of ActiveX controls at that time.
    A decade has passed, and now the stupid US law has been repealed. But the cryptography ActiveX industry has become so strong (probably bribing the high officers in the government), that all Korean sites are still using those kind of ActiveX controls. And
    you know, they require Windows and IE. Recently some sites started to support other browsers, but still the majority requires IE and ActiveX.
    So, if you live in Korea, you have no choice but to use IE on Windows to get things done, and almost all sites popup ActiveX installation dialogues constantly. If you do not change the security settings, when you approve the installation, the whole site
    refreshes. That is time-consuming and frustrating. 
    To keep my mental heath, I deal with all Korean sites in a virtual machine. To avoid the refresh problem, I have changed the security settings from "prompt" to "enable". The "Your security is at risk..." banner at the bottom
    of IE is surely annoying. I hope Microsoft let us either remove that banner or remove the support of ActiveX controls altogether.

  • "Your current color settings discard CMYK profiles in linked content" error message

    I keep getting the following error message:
    "Your current color settings discard CMYK profiles in linked content but profiles were set to be honored when this document was created."
    every time I open an Illustrator document. I have no idea how this setting was set and no idea how to turn it off. I am just using the standard N America Prepress color setting in Bridge.
    I have tried opening new documents using the supplied Ai CS4 new document profiles, no luck. So I am assuming it's a pref that is set in the app itself, yet I have no idea how to change this setting? I don't even see anything referring to a setting like this.
    I found this archived discussion: http://www.adobeforums.com/webx?128@@.59b58d84 which had no resolution. Thought I would throw it out there again and see if anyone has been able to fix this. It drives me insane having to deal with that error every time I open a saved document.

    To disable the alert via scripting you can use the following line:
    app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;
    Put it in a function with null return and call the fuction where you want to supress any error dialog.
    Mind you this would supress all the alert dialogs of the Illustrator App. 

  • Detecting client proxy settings

    Dear All,
    Can anyone tell me how to detect client proxy settings from a java application (not in a browser).
    I tried System.getProperties().getProperty("http.proxyhost") without success.
    Our application is distribuited using Java Web Start technology and needs to know proxy settings to connect to the remote host thru an unknown proxy server.
    Solution to this problem is very important and urgent! Please help me!
    Thanks in advance!

    Look for
    proxyHost
    proxyPort
    or (for https)
    https.proxyHost
    https.proxyPort

  • My Win7 Ultimate will not allow LR4 to download.Note:Current security settings won't allow.

    My Win7 Ultimate will not allow LR4 to download. Message is"current security settings do not allow file to be downloaded". I have shut down all antivirus programs...still no luck. ?What to do?

    More detail about your scenario is needed:
    Windows 7 doesn’t download anything, itself.  If you are using a browser to download and it is a browser security message then poke around in the browser settinsg to see if you can see a setting to enable or disable to allow downloads.  If you are in a managed network environment it is possible that the downloads are disabled by a group policy that cannot be overridden by the normal user and you’d have to take up your issue with your supervisor or network administration personnel.
    Assuming you’re using Internet Explorer, you might also just try another browser, like Firefox or Chrome available that might have more relaxed security settings.
    The source of the message should be somewhat obvious and whatever is issuing the message is the thing to tweak the settings of.  This really isn’t a Windows Security forum so don’t expect anyone to give you click-by-click instructions for each browser type and version.

  • How to detect Current Selection in a TextBox

    Hi All,
    I faced an issue regarding how to detect current selection in a Word Document TextBox. The Document looks like this,
    I tried to use Application_WindowSelectionChange(Word.Selection Sel)
    event to handle,
    private void Application_WindowSelectionChange(Word.Selection Sel)
    if (Sel.Range.ShapeRange.Count != 0)
    return;
    I found Sel.Range.ShapeRange.Count always 0. 
    To reproduce this issue, I upload the test document in OneDrive, you can download from
    here.
    How to solve this issue?
    Thanks a lot!
    The future belongs to those who believe in the beauty of their dreams.

    Hi friend,
    Just use Sel.ShapeRange.Count instead.
    On the other hand, to get selected text, we could use Sel.Text, to get whole selected
    TextBox’s text, we could use Sel.ShapeRange.TextFrame.TextRange.Text.
    Good job!
    Regards
    Starain
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

Maybe you are looking for

  • Enable drill through feature in a Financial Reporting Report

    Hi, my Hyperion system version is 9.3.1. I need to realize some Financial Reporting reports using the Drill Through feature but i don't know how activate this feature. Anybody can hel me? Thanks in advance. Stefano

  • How to access XML files on public part of an external library DC?

    Hi, I would like to put xml and xsd files into a public part of an external library DC, so that I can access these files within other DCs. But I don't know the path which I have to use in the other DCs, e.g. for creating a File object from such xml o

  • Why is my outgoing server not working?

    I have my laptop apple mail set up with a few accounts. Im able to get incoming mail but i cant send emails. It says the server is not working. What can i do to fix this issue?

  • I don't want simplfield Chinese on my mac.

    Hello, I've choose English as system language, these simplfield chinese is so bothering. Somebody help? Appreciate!

  • Dock gone / Can't log out / No Dashboard

    In activity monitor my Dock App is using 99 CPU? (if that means anything) when I try to change the preferences of the dock it takes a while to respond but lets me change it just nothing happens. Dashboard doesn't work or spaces and I can't minimize a