Skip to content
Archive of posts filed under the Tips category.

@@servername

If @@servername returns null or return wrong host name, execute below mentioned sql Query. DECLARE @Current SysName Select @Current = Convert(varchar(128), SERVERPROPERTY(‘ServerName’) ) IF(@Current <> @@SERVERNAME) BEGIN EXEC sp_dropserver @@SERVERNAME EXEC sp_addserver @server=@Current,@local = ‘local’ EXEC master..xp_cmdshell ‘ECHO NET STOP MSSQLSERVER > restartSQL.bat’, no_output EXEC master..xp_cmdshell ‘ECHO NET START MSSQLSERVER >> restartSQL.bat’, no_output EXEC master..xp_cmdshell [...]

Export data from corrupted database

Below is the sql script to import data from source database into target database, It is assumed that you have both the databases on single server.The source database is current database & few tables are corrupted whereas the traget database is created from old backup for target database.since their is corruption ,it is not possible [...]

Compare DB – record counts

Code snippet will loop through all tables of Database SOURCEDB and compare record counts with tables in TARGETDB database USE SOURCEDB EXEC SP_MSforeachtable ‘DECLARE @OriCount INT      DECLARE @Count INT      DECLARE @Name VARCHAR(400)      SET @Count = (SELECT COUNT(*) FROM TARGETDB.?)      SET @OriCount = (SELECT COUNT(*) FROM SOURCEDB.?)      SET @Name=”?” IF(@Count <> @OriCount) BEGIN          [...]

Custom Domain Service Factory

Parameterized constructors are not allowed in WCF RIA domain service, however your object model may requires to have constructor with arguments. For example EmployeeService (in this example) is WCF RIA Domain Service which requires Authentication and have constructor with authenticated User instance as parameter. The activate the service in such scenario you need to provide [...]

SQL Server Discovery

The objective of this article is to discover the presence of Microsoft SQL Server  across subnet. There are API’s to enumerate SQL Server instances in single subnet (Win32 API : NetServerEnum ) and Microsoft enterprise manger uses this API to populate the list of SQL server available in current subnet. The API NetServerEnum broadcast UDP packets [...]

Silverlight data grid extensions

Data Grid Ex Support two new events Commit (An event that indicates that a selection is complete and has been made, effectively commit action.) Cancel (An event that indicates that the selection operation has been canceled) Also supports single row double click. Event Commit will be raise if user double click on row or press enter while row [...]

LINQ Dynamic Query

LINQ dynamic query code //Input : str=> string to search some text (First Name,Last Name,Date of Birth(dd/mm/yyyy) or post code) in any order; //output : result set str = str.ToLower().Replace("  ", " ").Trim(); IList<vw_patient> patients = App.Patients; string[] parts = str.Split(" ".ToCharArray(),StringSplitOptions.RemoveEmptyEntries); Func<vw_patient, bool> predicate = null; foreach (string part in parts) {     long [...]

Capitalization of string

To convert string to title case (capitalize initial letters of the string), there is not string method to call. However, we can use the CultureInfo from Globalization and use the TextInfo’s ToTitleCase method. Here is how it can be done in C#: Add class StringExtensions to your root namespace and copy the code,All string variables [...]