Tuesday, 18 October 2011

RAISERROR raises error - not expected behavior on SQL 2005

Description:
We all expect that RAISERROR raises error, but not like this one:

Script:
RAISERROR ('Error', 16, 255 );

Output:
Invalid value 255 for state. Valid range is from 0 to 127

Value for state can be from 0 to 255, according to BOL:
"state
Is an integer from 0 through 255. Negative values or values larger than 255 generate an error.
If the same user-defined error is raised at multiple locations, using a unique state number for each location can help find which section of code is raising the errors."

Solution:
- check SQL Server version (@@VERSION) and if it's 9.0.1399 (Microsoft Sql Server 2005 RTM) it's really time to apply some service pack. SQL 2005 RTM was released on November 7, 2005! ;)

Links:
- http://sqlserverbuilds.blogspot.com/ (list of SQL Server builds)
- http://www.microsoft.com/download/en/details.aspx?id=7218 (Download Microsoft SQL Server 2005 Service Pack 4 RTM)
- http://support.microsoft.com/kb/2507769/ (Cumulative update package 3 for SQL Server 2005 Service Pack 4)

Appendix:
- error in German language version:"Der Wert 255 für den Status ist ungültig. Der gültige Bereich liegt zwischen 1 und 127."

Tuesday, 4 October 2011

Kids don't delete LDF files!

If you have, and no backup etc, read following articles:

try with "CREATE DATABASE name ON fileMDB FOR ATTACH_REBUILD_LOG"
http://social.msdn.microsoft.com/forums/en-US/sqldisasterrecovery/thread/d48bb79b-0403-46d8-abb9-11fff40e7e72/

in case of opened transactions (error:" The protocol can not be rebuilt because there were open on shutdown of database transactions / users that no probe was used for the database or the database was write protected. This error can occur if the transaction log file was manually deleted or lost due to hardware failure or external failure.")

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=114812
http://stackoverflow.com/questions/773059/how-to-recover-database-from-mdf-in-sql-server-2005

Uncommited transacions will appear in recovered databases.

Monday, 26 September 2011

Thursday, 22 September 2011

SQL @@SERVERNAME can return NULL, but it should not

Probably we are all using "@@SERVERNAME" variable for geting SQL Server name and usually it does what we expect.

Today some custom maintenance procedures stoped working. After investigation I've noticed that SELECT @@SERVERNAME returns "NULL".

Background: @@SERVERNAME gets value (at SQL Server boot) from table sys.servers where server_id is equal to 0.

SELECT [name] FROM sys.servers WHERE server_id = 0

in this system table there are also linked servers and "my server" was there with server_id different than zero.

Solution:
EXEC master.dbo.sp_dropserver @server=N'serverName', @droplogins='droplogins'
EXEC sp_addserver 'serverName', LOCAL

and restart server.

Good workaround (probably best practice) is to use function ServerProperty('serverName').

More info at: http://randyjean.blogspot.com/2005/11/sql-servername-can-sometimes-return.html

PS Server is SQL Server 2005 Standard

Sunday, 18 September 2011

ASP.NET: Request for the permission of type 'System.Security.Permissions.FileIOPermission

Pri selitvi stare asp.net 2.0 aplikacije, k novemu gostitelju se mi je pojavila naslednja napaka:

Napaka (ob zagonu asp.net aplikacije):
Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet)
at System.Security.CodeAccessPermission.Demand()
at System.IO.Directory.GetCurrentDirectory()
at System.Security.Cryptography.Xml.Reference.CalculateHashValue(XmlDocument document, CanonicalXmlNodeList refList)
at System.Security.Cryptography.Xml.SignedXml.BuildDigestedReferences()
at System.Security.Cryptography.Xml.SignedXml.ComputeSignature()
at xPortTools.xPortTools3.GenerateLicense(String lcHash, String ProductId, String lcToken, String lcKey, String lcHeader, String lcSupport, String lcWeb, String lcManufacturer, String lcManufacturerEmail, String lcCopyright, String lcDescription, Boolean Demo, DateTime ldActivationDate, String CdKey)
"
Rešitev:
Namesto "System.Web.Configuration.WebConfigurationManager" uporabi "System.Configuration.ConfigurationManager". Strežnik je nastavljen na "medium trust" in preprečuje uporaba "WebConfigurationManger".

Vir:
http://support.jodohost.com/showthread.php?t=11131

Sunday, 24 July 2011

VirtualBox 4 - sprememba velikosti diska VDU

Problem:
- zmanjkuje prostora v virtualnem disku

Rešitev:
- VirtualBox verzija 4 podpira razširjanje (resize) VDI datotek, uporabimo ukaz VBoxManage, parametri so naslednji:
C:\Program Files\Oracle\VirtualBox VBoxManage modifyhd "polna pot do\ime.vdi" --resize novavelikostvMB

- novavelikostvMB (npr. 40000 za slabih 40GB)
- pot do "VBoxMange.exe" se lahko razlikuje
- v trenutni verziji je podprto samo razširjanje diska (expand), zmanjševanje (compact) še ne
- ostane še razširitev diska v operacijskem sistemu

Thursday, 21 July 2011

Zelo počasno odpiranje Excel datotek iz omrežja (mrežnega diska)

Simptomi:
- skušamo odpreti Excel (2003) datoteko iz mrežnega diska (npr. F:), dolgo časa se ne zgodi nič, kaže, da je Excel že zamrznil, nato pa se le končno odpre, pred nekaj dnevi je vse delovalo OK
- datoteko iz mrežnega diska skopiramo na lokalni disk (npr. c:), tam se odpre brez zakasnitve

Vzrok:
- pred kratkim je bil naložen popravek "Office File Validation Add-in"

Rešitev:
- izklop preko navodil članka 2570623, klik na mojstra "FixIT"
- v tem članku se nahaja tudi registerski ključ za izklop (primerzno namestitev, preko skripte, na več računalnikov)