Specify to Run Server Garbage Collection (gcServer)

To enable Garbage Collector to work in server mode put follwing section in config:

<runtime>
  <gcServer enabled="true" />
</runtime>

When to use:

  • On computers with more  than two cores.
  • You have multithreaded service not hosted in IIS.

Typical candidate: self-hosted WCF service.
This option improves service performance and consumes more memory.

For details see:

Advertisements

MS SQL – Get Installed Languages (Transact-SQL)

Useful query to list installed language codes:

select alias, msglangid from sys.syslanguages;

See more on MSDN: http://msdn.microsoft.com/en-us/library/ms190303.aspx

Create/Drop MS SQL FullText Catalog & Index (Transact-SQL)

-- Change default full-text language to Neutral!
-- It can be skipped, if specific language code will be provided when creating index.

USE Master
EXEC sp_configure 'show advanced option', '1';
RECONFIGURE WITH OVERRIDE;
GO
EXEC sp_configure 'default full-text language', '0';
RECONFIGURE WITH OVERRIDE;
GO

USE [MyFulltextDatabase]
GO

-- Drop catalog if was created
-- Drop indexes first

IF  EXISTS (SELECT * FROM sys.fulltext_indexes fti WHERE fti.object_id = OBJECT_ID(N'[dbo].[MyTable]'))
   ALTER FULLTEXT INDEX ON [dbo].[MyTable] DISABLE
GO

IF  EXISTS (SELECT * FROM sys.fulltext_indexes fti WHERE fti.object_id = OBJECT_ID(N'[dbo].[MyTable]'))
   DROP FULLTEXT INDEX ON [dbo].[MyTable]
GO

IF  EXISTS (SELECT * FROM sysfulltextcatalogs ftc WHERE ftc.name = N'FullTextCatalog')
   DROP FULLTEXT CATALOG [FullTextCatalog]
GO

-- Create new catalog in current database

CREATE FULLTEXT CATALOG [FullTextCatalog]
ON FILEGROUP [PRIMARY]
WITH ACCENT_SENSITIVITY = OFF
AS DEFAULT
AUTHORIZATION [dbo]
GO

-- Create a new index on the specified table

CREATE FULLTEXT INDEX
	ON [dbo].[MyTable]
	KEY INDEX [PrimaryKeyName]
	ON [MyFulltextDatabase]
	WITH CHANGE_TRACKING AUTO
GO
ALTER FULLTEXT INDEX ON [dbo].[MyTable] ADD ([MyColumn1] LANGUAGE 0x0)
GO
ALTER FULLTEXT INDEX ON [dbo].[MyTable] ADD ([MyColumn2] LANGUAGE 0x0)
GO

More info about FullText indexes: http://msdn.microsoft.com/en-us/library/ms187317.aspx

Encrupt/Protect Custom Configuration Section

Illustrates how to encrypt custom configuration section in the service OnStart event:

protected override void OnStart(string[] args)
{
	try
	{			    
		string sectionName = "SectionNameToSecure";
		
		Configuration config = 
				ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
		ConfigurationSection section = config.GetSection(sectionName);
		if (!section.SectionInformation.IsProtected)
		{
			section.SectionInformation.ProtectSection("RsaProtectedConfigurationProvider");
			section.SectionInformation.ForceSave = true;
			config.Save(ConfigurationSaveMode.Full);

			// Reset configuration object!
			ConfigurationManager.RefreshSection(sectionName);
		}                
	}
	catch (Exception ex)
	{
		// Do exception tracing here
		this.Stop();
	}
}

SubSonic – Custom Query

SubSonic – how to execute custom query using QueryCommand and read a value from single row:

string result = String.Empty;
int id = 1;
string sqlCommand = "select Col1 from Table1 where id = @IdParam";

QueryCommand cmd = new QueryCommand(sqlCommand);

// Remember to set provider name in case if multiple databases are being
// used in the current project
// (because DataService remembers the latest executed connection string)!
cmd.ProviderName = DBTable1.Schema.Provider.Name;

cmd.AddParameter("@IdParam", id, DbType.Int32);

using (IDataReader rdr = DataService.GetReader(cmd))
{
    if (rdr.Read())
    {
        result = Convert.ToString(rdr[rdr.GetOrdinal("Col1")]);
    }
    rdr.Close();
}

SharePoint Guidance Links

Useful links:

Call WCF service – error handling & disposing

The final example how to correctly call WCF service and end communication if error occurred:

ServiceClient proxy = null;
bool success = false;
try
{
   proxy = new ServiceClient();
   proxy.ServiceMethod();
   proxy.Close();
   success = true;
}
finally
{
   // if failed and not null
   if (!success && proxy != null)
   {
      proxy.Abort();
   }
}

Remember always call Close to end communication. In other case it will can cause to crash server host (IIS for example) after reaching threads or memory limit.

Avoid to call non-IIS WCF service by using the using statement syntax. It will hide the actual communication exceptions details if server side error occurred.

Posted in WCF. Tags: . Leave a Comment »