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