11/04/2010

The server committed a protocol violation

Still valid for Visual Studio 2010, .NEt 4.0 and Skype.
Error: The server committed a protocol violation by Martin Kulov.

June 14, 2006

Skype nearly got me into screaming this night. I was debugging an ASP.NET 2.0 problem and at some time the IIS started to behave very strange. The debugging in Visual Studio failed with error “Unable to start debugging on the web server. The server committed a protocol violation. Section=ResponseStatusLine” and any attempt to load a page from the local IIS server returned an empty page even for those that did not exist :). At some time (couple of hours lost) I saw in the IIS Management Console that the web site was not running at all. When I tried to start it I got the error “Unexpected Error 0x8ffe2740 Occurred” and the long awaited event log entry (there was no entry at the time I tried to start the web site) – Event ID: 115 Description: “The service could not bind instance 1.”. A quick google showed that this error is due to already opened port 80 and the web server just could not open and use that port. Indeed netstat –a showed that port 80 is already opened but there was no way to see who was using it. This is where TCPView, marvelous tool from Sysinternals, helped a lot (Update: I just found that netstat –b would display the owning processes of each connection.). There was Skype listening on port 80, obviously taken ownership of the socket during the number of restarts when I was debugging. How stupid is that?Attention to all web developers who are using Skype! Make sure to uncheck the option for using port 80 and 443 from Tools\Options\Connection dialog.

10/25/2010

Locking in Microsoft SQL Server

Alexander Chigrik
chigrik@mssqlcity.com


Introduction

Transaction Isolation Levels

Lock types

Locking optimizer hints

Deadlocks

View locks (sp_lock)

Literature


Introduction

In this article, I want to tell you about SQL Server 7.0/2000 Transaction Isolation Levels, what kinds of Transaction Isolation Levels exist, and how you can set the appropriate Transaction Isolation Level, about Lock types and Locking optimizer hints, about deadlocks, and about how you can view locks by using the sp_lock stored procedure.

Transaction Isolation Levels

There are four isolation levels:

·  READ UNCOMMITTED

·  READ COMMITTED

·  REPEATABLE READ

·  SERIALIZABLE

Microsoft SQL Server supports all of these Transaction Isolation Levels and can separate REPEATABLE READ and SERIALIZABLE.

Let me to describe each isolation level.

READ UNCOMMITTED

When it's used, SQL Server not issue shared locks while reading data. So, you can read an uncommitted transaction that might get rolled back later. This isolation level is also called dirty read. This is the lowest isolation level. It ensures only that a physically corrupt data will not be read.

READ COMMITTED

This is the default isolation level in SQL Server. When it's used, SQL Server will use shared locks while reading data. It ensures that a physically corrupt data will not be read and will never read data that another application has changed and not yet committed, but it not ensures that the data will not be changed before the end of the transaction.

REPEATABLE READ

When it's used, the dirty reads and nonrepeatable reads cannot occur. It means that locks will be placed on all data that is used in a query, and another transactions cannot update the data.

This is the definition of nonrepeatable read from SQL Server Books Online:

nonrepeatable read

When a transaction reads the same row more than one time, and between the

two (or more) reads, a separate transaction modifies that row. Because the

row was modified between reads within the same transaction, each read

produces different values, which introduces inconsistency.

SERIALIZABLE

Most restrictive isolation level. When it's used, the phantom values cannot occur. It prevents other users from updating or inserting rows into the data set until the transaction will be completed.

This is the definition of phantom from SQL Server Books Online:

phantom

Phantom behavior occurs when a transaction attempts to select a row that

does not exist and a second transaction inserts the row before the first

transaction finishes. If the row is inserted, the row appears as a phantom

to the first transaction, inconsistently appearing and disappearing.

You can set the appropriate isolation level for an entire SQL Server session by using the SET TRANSACTION ISOLATION LEVEL statement.
This is the syntax from SQL Server Books Online:

SET TRANSACTION ISOLATION LEVEL

    {

        READ COMMITTED

        | READ UNCOMMITTED

        | REPEATABLE READ

        | SERIALIZABLE

    }

You can use the DBCC USEROPTIONS statement to determine the Transaction Isolation Level currently set. This command returns the set options that are active for the current connection. This is the example:

SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED

GO

DBCC USEROPTIONS

GO

Lock types

There are three main types of locks that SQL Server 7.0/2000 uses:

·  Shared locks

·  Update locks

·  Exclusive locks

Shared locks are used for operations that do not change or update data, such as a SELECT statement.

Update locks are used when SQL Server intends to modify a page, and later promotes the update page lock to an exclusive page lock before actually making the changes.

Exclusive locks are used for the data modification operations, such as UPDATE, INSERT, or DELETE.

Shared locks are compatible with other Shared locks or Update locks.

Update locks are compatible with Shared locks only.

Exclusive locks are not compatible with other lock types.

Let me to describe it on the real example. There are four processes, which attempt to lock the same page of the same table. These processes start one after another, so Process1 is the first process, Process2 is the second process and so on.

Process1 : SELECT
Process2 : SELECT
Process3 : UPDATE
Process4 : SELECT

Process1 sets the Shared lock on the page, because there are no another locks on this page.
Process2 sets the Shared lock on the page, because Shared locks are compatible with other Shared locks.
Process3 wants to modify data and wants to set Exclusive lock, but it cannot make it before Process1 and Process2 will be finished, because Exclusive lock is not compatible with other lock types. So, Process3 sets Update lock.
Process4 cannot set Shared lock on the page before Process3 will be finished. So, there is no Lock starvation. Lock starvation occurs when read transactions can monopolize a table or page, forcing a write transaction to wait indefinitely. So, Process4 waits before Process3 will be finished.
After Process1 and Process2 were finished, Process3 transfer Update lock into Exclusive lock to modify data. After Process3 was finished, Process4 sets the Shared lock on the page to select data.

Locking optimizer hints

SQL Server 7.0/2000 supports the following Locking optimizer hints:

·  NOLOCK

·  HOLDLOCK

·  UPDLOCK

·  TABLOCK

·  PAGLOCK

·  TABLOCKX

·  READCOMMITTED

·  READUNCOMMITTED

·  REPEATABLEREAD

·  SERIALIZABLE

·  READPAST

·  ROWLOCK

NOLOCK is also known as "dirty reads". This option directs SQL Server not to issue shared locks and not to honor exclusive locks. So, if this option is specified, it is possible to read an uncommitted transaction. This results in higher concurrency and in lower consistency.

HOLDLOCK directs SQL Server to hold a shared lock until completion of the transaction in which HOLDLOCK is used. You cannot use HOLDLOCK in a SELECT statement that includes the FOR BROWSE option. HOLDLOCK is equivalent to SERIALIZABLE.

UPDLOCK instructs SQL Server to use update locks instead of shared locks while reading a table and holds them until the end of the command or transaction.

TABLOCK takes a shared lock on the table that is held until the end of the command. If you also specify HOLDLOCK, the lock is held until the end of the transaction.

PAGLOCK is used by default. Directs SQL Server to use shared page locks.

TABLOCKX takes an exclusive lock on the table that is held until the end of the command or transaction.

READCOMMITTED
Perform a scan with the same locking semantics as a transaction running at the READ COMMITTED isolation level. By default, SQL Server operates at this isolation level.

READUNCOMMITTED
Equivalent to NOLOCK.

REPEATABLEREAD
Perform a scan with the same locking semantics as a transaction running at the REPEATABLE READ isolation level.

SERIALIZABLE
Perform a scan with the same locking semantics as a transaction running at the SERIALIZABLE isolation level. Equivalent to HOLDLOCK.

READPAST
Skip locked rows. This option causes a transaction to skip over rows locked by other transactions that would ordinarily appear in the result set, rather than block the transaction waiting for the other transactions to release their locks on these rows. The READPAST lock hint applies only to transactions operating at READ COMMITTED isolation and will read only past row-level locks. Applies only to the SELECT statement.
You can only specify the READPAST lock in the READ COMMITTED or REPEATABLE READ isolation levels.

ROWLOCK
Use row-level locks rather than use the coarser-grained page- and table-level locks.

You can specify one of these locking options in a SELECT statement.
This is the example:

SELECT au_fname FROM pubs..authors (holdlock)

Deadlocks

Deadlock occurs when two users have locks on separate objects and each user wants a lock on the other's object. For example, User1 has a lock on object "A" and wants a lock on object "B" and User2 has a lock on object "B" and wants a lock on object "A". In this case, SQL Server ends a deadlock by choosing the user, who will be a deadlock victim. After that, SQL Server rolls back the breaking user's transaction, sends message number 1205 to notify the user's application about breaking, and then allows the nonbreaking user's process to continue.

You can decide which connection will be the candidate for deadlock victim by using SET DEADLOCK_PRIORITY. In other case, SQL Server selects the deadlock victim by choosing the process that completes the circular chain of locks.

So, in a multiuser situation, your application should check the error 1205 to indicate that the transaction was rolled back, and if it's so, restart the transaction.

Note. To reduce the chance of a deadlock, you should minimize the size of transactions and transaction times.

View locks (sp_lock)

Sometimes you need a reference to information about locks. Microsoft recommends using the sp_lock system stored procedure to report locks information. This very useful procedure returns the information about SQL Server process ID, which lock the data, about locked database, about locked table ID, about locked page and about type of locking (locktype column).

This is the example of using the sp_lock system stored procedure:

spid   locktype                            table_id    page        dbname

------ ----------------------------------- ----------- ----------- ---------------

11     Sh_intent                           688005482   0           master

11     Ex_extent                           0           336         tempdb

The information, returned by sp_lock system stored procedure needs in some clarification, because it's difficult to understand database name, object name and index name by their ID numbers.

Check the link below if you need to get user name, host name, database name, index name object name and object owner instead of their ID numbers:
Detailed locking view: sp_lock2

Literature

1. SQL Server Books Online

2.
Transaction Isolation Level

3.
Locking in SQL Server 6.5

4.
Detailed locking view: sp_lock2

5.
INF: Analyzing and Avoiding Deadlocks in SQL Server

9/05/2010

Microsft Online Services

Microsft Online Services is bedrijfssoftware dat door Microsoft wordt aangeboden en gehost als online services. Partners verkopen het als abonnement. Microsft Online Services past in Microsoft's 3-screens-and-a-cloud visie. Dit betekent dat software op de client, web browser en mobile beschikbaar moet zijn, zowel on-premise als online.

De online services bestaan uit de volgende producten en product suites:

Exchange Hosted Services beveiligt elektronische communicatie en e-mail met services voor het filteren van virussen, wormen, DOS-aanvallen en spam, het versleutelen van gegevens en het naleven van archiveringsvereisten.

Windows Azure is een besturingssysteem met cloudservices dat dient als omgeving voor ontwikkeling, servicehosting en servicebeheer voor het Windows Azure-platform. Windows Azure biedt ontwikkelaars on-demand reken- en opslagcapaciteit voor het online hosten, schalen en beheren van webtoepassingen via datacenters van Microsoft.

Office Live Meeting maakt het mogelijk te vergaderen met collega's en te communiceren met klanten via real-time vergaderingen, trainingssessies en gebeurtenissen.

Exchange Online is ontwikkeld om snel chatberichten te verzenden, zodat werknemers online toegang hebben tot gedeelde agenda's en contactpersonen.

SharePoint Online is een zeer veilige, centrale locatie waar werknemers efficiënt kunnen samenwerken, organisatiebronnen kunnen vinden en de inhoud en de workflow kunnen beheren.

Office Communications Online maakt medewerkers productiever door chatberichten met aanwezigheidsstatus in een veilige omgeving te verzenden. Verbindingen tussen mensen zijn daardoor sneller en efficiënter.

De Microsoft Business Productivity Online Standard Suite biedt gehoste oplossingen voor communicatie en samenwerking. Deze kenmerken zich door een hoge beschikbaarheid, uitgebreide beveiliging en eenvoudiger IT-beheer.

In de huidige internationale markt met veel concurrentie is behoefte ontstaan aan goedkope technologie die flexibiliteit biedt en waarde toevoegt aan organisaties.

De suite bestaat uit:
Microsoft Exchange Online
Microsoft SharePoint Online
Microsoft Office Live Meeting
Microsoft Office Communications Online

Vanaf €8,52 (ex. btw) per gebruiker per maand kan van de BPOS suite gebruik worden gemaakt.
Zie: De Microsoft Business Productivity Online Standard Suite biedt gehoste oplossingen voor communicatie en samenwerking

Tot slot is het mogelijk Microsoft ForeFront Online Protection for Exchange dienst (FOPE) af te nemen. na het aanvragen van een wacthwoord kunt u op https://admin.messaging.microsoft.com/ verder terecht.
Link naar Microsoft Online Services: http://www.microsoft.com/online/nl-nl/about.mspx

8/30/2010

Open Data Protocol (OData)

Open Data Protocol (OData)

There is a vast amount of data available today and data is now being collected and stored at a rate never seen before. Much, if not most, of this data however is locked into specific applications or formats and difficult to access or to integrate into new uses.
The Open Data Protocol (OData) is a Web protocol for querying and updating data that provides a way to unlock your data and free it from silos that exist in applications today. OData does this by applying and building upon Web technologies such as HTTP, Atom Publishing Protocol (AtomPub) and JSON to provide access to information from a variety of applications, services, and stores. The protocol emerged from experiences implementing AtomPub clients and servers in a variety of products over the past several years. OData is being used to expose and access information from a variety of sources including, but not limited to, relational databases, file systems, content management systems and traditional Web sites.
OData is consistent with the way the Web works - it makes a deep commitment to URIs for resource identification and commits to an HTTP-based, uniform interface for interacting with those resources (just like the Web). This commitment to core Web principles allows OData to enable a new level of data integration and interoperability across a broad range of clients, servers, services, and tools.
OData is released under the Open Specification Promise to allow anyone to freely interoperate with OData implementations.
New: Join the OData mailing list to ask questions about the protocol and discuss how it should evolve over time.

MS SQL Server stored procedure sp_msforeachdb

De volgende MS  SQL Server stored procedure voert een query uit voor alle databases:

exec sp_msforeachdb 'use [?] select db_name() dbcc showfilestats '

6/16/2010

SubMain has recently acquired GhostDoc

SubMain has recently acquired GhostDoc. We will continue to maintain and distribute the product free of charge. We will be improving GhostDoc and we always welcome the community feedback. If you have ideas, please post them in the GhostDoc forum. Roland Weigelt is the original author of GhostDoc and his web site can be found at http://roland-weigelt.de/.

3/11/2010

Script Editors

Goede script vbscript-editors zijn verkrijgbaar via Adersoft. Nu is er vbsedit 4.0 en htaedit 3.0. Beide zijn in 1 download te verkrijgen. De nieuwe versies vereisen geen Microsoft Script Debugger meer. Ook zijn er 64-bit versies van. Kijk verder op www.vbsedit.com en www.htaedit.com.

 

Microsoft heeft als onderdeel van Office 2007 ook een script editor bijgeleverd. Deze is standaard te vinden op

C:\Program Files\Common Files\microsoft shared\OFFICE12\MSE7.EXE.

3/10/2010

ASP Debugging

Introduction

This is a step by step guide on how to set up your project so you can debug a site written in classic ASP VBScript using Visual Studio 2008.

Using the Code

I walk you step by step through how to set up your project so you can debug a site written in classic ASP VBScript using Visual Studio 2008.

1.1 Setup IIS

1.1.1 Configure Default IIS web site on a local machine to point to the directory the Classic ASP web site is in and turn on ASP server side debugging:

iis-enable-asp-server-side-debugging.gif

1.2 Setup Project in Visual Studio 2008

Since we're talking "classic ASP" written in VBScript, you'll already have a web site. So I'll cover opening an existing site.

1.2.1 Launch Visual Studio 2008

1.2.2 File >> Open >> Web Site

1.2.3 Navigate to the directory that contains the ancient code you have to work with, select it and it opens.

1.2.4 Right click the web site in Solution Explorer

1.2.5 Go to Properties >> Start Options

1.2.6 Configure it to use custom server with Base URL of http://localhost

vs2008-start-options.gif

1.3 Start Debugger

1.3.1 Run application (F5)

1.3.2 Select Visual Studio 2008 as your debugger of choice

1.3.3 Attach to dllhost.exe

attach-to-dllhost.gif

1.3.4 Your browser launches

1.3.5 A new instance of Visual Studio launches

1.3.6 Close the new instance of Visual Studio but leave the browser open.

1.3.7 In the instance of Visual Studio that you opened the web site in, click Debug >> Attach to Process

1.3.8 Check Show process from all users

1.3.9 Select entry for dllhost.exe with type Script, T-SQL, x86

1.3.10 Click Attach

debug-attach-to-process.gif

1.3.11 Just to make sure things are in working order, set a break point at the beginning of your code and click refresh on the browser that was launched when you clicked F5.

1.3.12 Send me a nice thank you.

1.4 Restart Debugging Browser

You will need to reattach to the debugger process if you close the browser.

1.4.1 Hit F5 to launch a new browser window with your application in it. If it acknowledges your breakpoints, then never mind, you're already in business. If not then....

1.4.2 With the browser window still open back in Visual Studio, simply click Debug and then Attach to Process in the drop down menu.

1.4.3 Select entry for dllhost.exe with type Script, T-SQL, x86

1.4.4 Click Attach

1.4.5 Click refresh in the browser F5 launch and Bob's your uncle you're back in business.

 

3/09/2010

Data Execution Prevention (DEP) uitschakelen

Good news is that you can disable or turn off Data Execution Prevention (DEP) globally in Windows Vista. To stop the DEP protection, launch an elevated command prompt shell with administrative priviledges and credentials (log on to Windows Vista with a user account with administrator rights, and then right click on Command Prompt icon and select “Run as Administrator, or turn off UAC). Then execute the following command:

bcdedit.exe /set {current} nx AlwaysOff

If you regret your decision and now wants to enable or turn back on the DEP protection for your Windows Vista, simply use the following command instead:

bcdedit.exe /set {current} nx AlwaysOn

2/19/2010

Visual Studio 6 en Team Foundation Server Source Control

- Download Visual Studio Team Foundation Server MSSCCI Provider van Microsoft.
- In C:\Windows, open bestand vsaddin.ini.
- Voeg de regel "vbscc=3" toe.

2/17/2010

Definities bekijken in SQL Server

De tekst die een sql object definieert, kan worden verkregen via
SELECT TOP 10 Definition FROM sys.sql_modules

2/11/2010

ISO Drive Utilities

Dit zijn mogelijke opties:

Magic Disc MagicISO Virtual CD/DVD-ROM
BurnCDCC by TerabyteUnlimited
Virtual Clone Drive by Slysoft . Less then 1.5MB and compatible with Windows 7.