Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Checking for database concurrency violations

Checking for database concurrency violations

Scheduled Pinned Locked Moved C#
databasehelpsql-serversysadminjson
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    msx23
    wrote on last edited by
    #1

    In the app I'm writing I would like to be able to check if any concurrency violations have occurred on the database it's monitoring in the recent past. In SQL Server Management studio I can run the command DBCC CONCURRENCYVIOLATION which gives me the message back (where I forced concurrency violations): Concurrency violations since 2007-10-10 10:47:47.383 1 2 3 4 5 6 7 8 9 10-100 >100 4727 2800 1118 0 0 0 0 0 0 0 0 Concurrency violations will be written to the SQL Server error log. DBCC execution completed. If DBCC printed error messages, contact your system administrator. So this is the info I need, the way that I'm trying to get it into my program is: conn.Open(); conn.InfoMessage += new SqlInfoMessageEventHandler(SqlMessageEventHandler); SqlCommand c = new SqlCommand("DBCC CONCURRENCYVIOLATION", conn); c.ExecuteNonQuery(); where conn is my SQL connection and SqlMessageEventHandler grabs the error message: public void SqlMessageEventHandler(object sender, SqlInfoMessageEventArgs e) { string CVTest = ""; foreach (SqlError err in e.Errors) { CVTest += err.Message; } } The problem is that the "CVTest" sting I'm using to monitor the message only gives me back DBCC execution completed. If DBCC printed error messages, contact your system administrator.rather than the whole message as in Server Management Studio. This occurs whether the DB I'm checking has violations logged or not. Does anyone know how I can get all the information that DBCC CONCURRENCYVIOLATION should return? Alternatively, if anyone knows a better way to programatically check for concurrency violations that have occurred on the database that would be great, since parsing that message to determine can't be the most efficient way. Thank you.

    R 1 Reply Last reply
    0
    • M msx23

      In the app I'm writing I would like to be able to check if any concurrency violations have occurred on the database it's monitoring in the recent past. In SQL Server Management studio I can run the command DBCC CONCURRENCYVIOLATION which gives me the message back (where I forced concurrency violations): Concurrency violations since 2007-10-10 10:47:47.383 1 2 3 4 5 6 7 8 9 10-100 >100 4727 2800 1118 0 0 0 0 0 0 0 0 Concurrency violations will be written to the SQL Server error log. DBCC execution completed. If DBCC printed error messages, contact your system administrator. So this is the info I need, the way that I'm trying to get it into my program is: conn.Open(); conn.InfoMessage += new SqlInfoMessageEventHandler(SqlMessageEventHandler); SqlCommand c = new SqlCommand("DBCC CONCURRENCYVIOLATION", conn); c.ExecuteNonQuery(); where conn is my SQL connection and SqlMessageEventHandler grabs the error message: public void SqlMessageEventHandler(object sender, SqlInfoMessageEventArgs e) { string CVTest = ""; foreach (SqlError err in e.Errors) { CVTest += err.Message; } } The problem is that the "CVTest" sting I'm using to monitor the message only gives me back DBCC execution completed. If DBCC printed error messages, contact your system administrator.rather than the whole message as in Server Management Studio. This occurs whether the DB I'm checking has violations logged or not. Does anyone know how I can get all the information that DBCC CONCURRENCYVIOLATION should return? Alternatively, if anyone knows a better way to programatically check for concurrency violations that have occurred on the database that would be great, since parsing that message to determine can't be the most efficient way. Thank you.

      R Offline
      R Offline
      Robert Rohde
      wrote on last edited by
      #2

      I might be wrong but have you looked at what is inside the Message property of the SqlInfoMessageEventArgs in your case:

      public void SqlMessageEventHandler(object sender, SqlInfoMessageEventArgs e)
      {
      string CVTest = e.Message;
      foreach (SqlError err in e.Errors)
      CVTest += Environment.NewLine + err.Message;
      }

      Robert

      M 1 Reply Last reply
      0
      • R Robert Rohde

        I might be wrong but have you looked at what is inside the Message property of the SqlInfoMessageEventArgs in your case:

        public void SqlMessageEventHandler(object sender, SqlInfoMessageEventArgs e)
        {
        string CVTest = e.Message;
        foreach (SqlError err in e.Errors)
        CVTest += Environment.NewLine + err.Message;
        }

        Robert

        M Offline
        M Offline
        msx23
        wrote on last edited by
        #3

        Hey, thanks for the reply. Yeah, the Message property only contains that one line response as well instead of the whole message. Anyone have any other ideas on how to check for concurrency violations? Thanks

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups