SQL 2008 scope_identity() known bug

SQL Server upto 2008 (supposedly fixed in 2012) has a known bug regarding the scope_identity() function. It may return incorrect values when running a parallel insert.

Source:

http://connect.microsoft.com/SQL/feedback/ViewFeedback.aspx?FeedbackID=328811

 

Search for specific text in Stored Procedures

SELECT name

FROM sys.procedures

WHERE OBJECT_DEFINITION(OBJECT_ID) LIKE ‘%User_name()%’

Goal: look for “User_name()” in all the stored procedures
Result: the query will return the name of all the stored procedures containing this “User_name()” text.

 

MultiLine TextWrap Label

Label control does not support multi line text wrap feature, however TextBlock control does. To use TextWrap feature in label, set the following:

Invoke ButtonClick event from pressing a keyboard shortcut in XAML

To invoke button click event by:
pressing Enter key, set IsDefault=”True”
pressing Esc key, set IsCancel=”True”

Database Design

Top-down (Design by Analysis) – Requirements analysis, Logical DB design, Physical DB design

  • begins with the high-level conceptual design of the business model based on a defined set of requirements
  • develop a logical data model by group the attributes of real-world objects into relations or entities and define the relationship between them
  • remove redundancies, resolve complex relationships, add constraints
  • design the actual physical database based on the preceding logical design

Database design is the process of creating a business model that you use to convert business objects into database components (tables & views).  Data modeling aims to produce a complete, accurate, and consistent representation of objects and the relationships between them in the real world.

 

SQL DBCC Commands

DBCC FREEPROCCACHE [WITH NO_INFOMSGS]
DBCC FREESESSIONCACHE [WITH NO_INFOMSGS]
DBCC FREESYSTEMCACHE (‘ALL’) [ WITH  [MARK_IN_USE_FOR_REMOVAL] ,  [NO_INFOMSGS] ]

  • DBCC FREEPROCCACHE
    Remove all elements from the procedure cache.
  • DBCC FREESESSIONCACHE
    Flush the distributed query connection cache.
  • DBCC FREESYSTEMCACHE
    Release all unused cache entries from all caches.

Key:

  • NO_INFOMSGS
    Suppress all information messages
  • ALL
    All supported caches
  • MARK_IN_USE_FOR_REMOVAL
    Free up currently used entries asap (asynchronous), will not prevent new entries being created in the cache (Requires ALTER SERVER STATE permission on the server).

————————————————————————————————————————————————————-

CHECKPOINT [duration]

  • CHECKPOINT
    Write all dirty pages to disk
  • [duration]
    Time for checkpoint to complete

This will write to disk all those data pages in the buffer cache of the current database which have been modified, but not yet written to disk.

————————————————————————————————————————————————————-

DBCC DROPCLEANBUFFERS [WITH NO_INFOMSGS]

  • DBCC DROPCLEANBUFFERS
    Remove all clean buffers from the buffer pool
  • WITH NO_INFOMSGS
    Suppress all information messages

This command is useful to test queries with a cold buffer cache without shutting down and restarting the server.  To produce a ‘cold’ buffer cache with all dirty pages written to disk, first use CHECKPOINT.

————————————————————————————————————————————————————-

Refer to the links below for more information on DBCC commands:

http://ss64.com/sql/dbcc_free.html

http://ss64.com/sql/checkpoint.html

http://ss64.com/sql/dbcc_dropclean.html

Allowing only one instance of application to run per user

Instead of checking for process name and process owner, try Mutex.  Mutex, Mutual Exlusion, is synchronization primitive that can be used for inter-process synchronization (owned by a single thread at any given time). http://msdn.microsoft.com/en-us/library/system.threading.mutex.aspx

[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetForegroundWindow(IntPtr hWnd);
static void Main()
{
   bool createdNew = true;
   Mutex mutex = new Mutex(true, "ApplicationName", out createdNew)
   if (createdNew)
   {
      //start the application
   }
   else
   {
      //put the focus on the application
      Process current = Process.GetCurrentProcess();
      foreach (Process process in 
         Process.GetProcessesByName(current.ProcessName))
      {
         if (process.Id != current.Id)
         {
             SetForegroundWindow(process.MainWindowHandle);
             break;
         }
      }
   }
}

more detail: http://iridescence.no/post/CreatingaSingleInstanceApplicationinC.aspx

i3, i5 and i7

When Intel releases its new architecture, Sandy Bridge, Intel also releases its new processors: i3, i5 and i7.

i3 has dual core base, hyper threading support, and virtualization. It’s known to perform closely to lower end Core 2 Quad processors.

Comparing to i3, i5 will give a noticeable difference in term of speed. There are 2 type of i5: dual core (32nm technology, hyper threading support, virtualization support, and Turbo Boost technology) and quad core (45nm technology, virtualization support and Turbo Boost technology, but do not have hyper threading support).

Comparing to i5, i7 promises to be faster. However, unless you’re running an application that uses 8 threads, you won’t notice much differences between the two. There are two different chip sets for i7, LGA1156 (800s) or LGA1366 (900s).

—————–
Hyper-Threading is Intel’s simultaneous multi-threading technology that presents each physical core as two logical cores to an operating system.

Visual Studio 2010 Keyboard Shortcuts

Click here to download the shortcuts file from Microsoft website

Cannot open backup device. Operating system error 5

I’m trying to restore a database from .bak file and receive this error:
Cannot open backup device. Operating system error 5 (Access is denied). RESOTRE HEADERONLY is terminating abnormally. (Microsoft SQL Server, Error: 3201)

My attempts:

  1. Restart MS SQL Server Service using Local System Account with Allow service to interact with desktop checked. (failed)
  2. Make sure i have the right security on the .bak file by right click on the file > properties > Security tab > click Advanced button > and make sure Allow inheritable permissions from the parent to propagate to this object and all child objects. Include these with entries explicitly defined here. is checked. (worked)

I did both of these and it works.

« Older Entries