Wednesday, December 25, 2013

The database could not be exclusively locked to perform the operation. (Microsoft SQL Server, Error: 5030)


First we will see how to set the database to single user mode,

ALTER DATABASE dbName
SET SINGLE_USER WITH ROLLBACK IMMEDIATE

Now we will try to rename the database

ALTER DATABASE dbName MODIFY NAME = dbNewName


Finally we will set the database to Multiuser mode


ALTER DATABASE dbNewName
SET MULTI_USER WITH ROLLBACK IMMEDIATE


source :
http://weblogs.asp.net/varadam/archive/2012/08/10/the-database-could-not-be-exclusively-locked-to-perform-the-operation-microsoft-sql-server-error-5030.aspx

Wednesday, November 20, 2013

read only property and XmlSerializer

I had an issue serializing a class using the XmlSerializer, where the class had a collection property.

example:

public List<Employee> Subordinates { getprivate set; } 

if the property setter was public then everything works fine and the property serialized .
but if the property has a private setter then the following exception is thrown

Unable to generate a temporary class (result=1). error CS0200: Property or indexer '[namespace].Subordinates' cannot be assigned to -- it is read only

The problem was that the class exposed the collection property as a readonly property, but the XmlSerializer needs the property to be read/write access

so the solution is to make the property with public setter as follows
public List<Employee> Subordinates { getset; }  

Monday, January 7, 2013

Give user acess to a certification


When your application use certification and you have a windows service, and  you set the user of the windows service to be for example Network Service to be able to access resources on network by the windows service , you may get the following exception

It is likely that certificate 'CN=XX' may not have a private key that is capable of key exchange or the process may not have access rights for the private key. Please see inner exception for detail. Keyset does not exist

 

 That mean the Network Service account have no access for the certification

Then You have to give authority for the Network Service account to access your certification

Then you can use WinHttpCertCfg

WinHttpCertCfg.exe -g -c LOCAL_MACHINE\MY -s "IssuedToName" -a "AccountName"

Note AccountName is the name of a local computer account or a domain account. IssuedToName is the name of the company or domain to which the client certificate was issued.

 

Reference