Friday, November 28, 2014

C# Code to get Last day of a month


 
  Method Name : DateTime.DaysInMonth()
  int DateTime.DaysInMonth(year,month)
  Eg:

  txtNoOfDays.Text = DateTime.DaysInMonth(Convert.ToDateTime(txtDate.Text).Year, Convert.ToDateTime(txtDate.Text).Month).ToString();  


Saturday, November 8, 2014

Cannot find template file for the new query [Solved]


Error
Cannot find template file for the new query (‘C:\Program Files\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\SqlWorkbenchProjectItems\SQL\SQLFile.sql’)
Solution:
Step 1: Go to C:\Program Files\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\SqlWorkbenchProjectItems\SQL\
Step 2: Create .SQL File named SQLFile.SQL

Thursday, November 6, 2014

Tuesday, November 4, 2014

Drop all the tables, stored procedures, triggers, constraints and all the dependencies in one sql statement


 /* Drop all non-system stored procs */  

 DECLARE @name VARCHAR(128)  
 DECLARE @SQL VARCHAR(254)  
 SELECT @name = (SELECT TOP 1 [name] FROM sysobjects WHERE [type] = 'P' AND category = 0 ORDER BY [name])  
 WHILE @name is not null  
 BEGIN  
   SELECT @SQL = 'DROP PROCEDURE [dbo].[' + RTRIM(@name) +']'  
   EXEC (@SQL)  
   PRINT 'Dropped Procedure: ' + @name  
   SELECT @name = (SELECT TOP 1 [name] FROM sysobjects WHERE [type] = 'P' AND category = 0 AND [name] > @name ORDER BY [name])  
 END  
 GO  

 /* Drop all views */  

 DECLARE @name VARCHAR(128)  
 DECLARE @SQL VARCHAR(254)  
 SELECT @name = (SELECT TOP 1 [name] FROM sysobjects WHERE [type] = 'V' AND category = 0 ORDER BY [name])  
 WHILE @name IS NOT NULL  
 BEGIN  
   SELECT @SQL = 'DROP VIEW [dbo].[' + RTRIM(@name) +']'  
   EXEC (@SQL)  
   PRINT 'Dropped View: ' + @name  
   SELECT @name = (SELECT TOP 1 [name] FROM sysobjects WHERE [type] = 'V' AND category = 0 AND [name] > @name ORDER BY [name])  
 END  
 GO  
 /* Drop all functions */  

 DECLARE @name VARCHAR(128)  
 DECLARE @SQL VARCHAR(254)  
 SELECT @name = (SELECT TOP 1 [name] FROM sysobjects WHERE [type] IN (N'FN', N'IF', N'TF', N'FS', N'FT') AND category = 0 ORDER BY [name])  
 WHILE @name IS NOT NULL  
 BEGIN  
   SELECT @SQL = 'DROP FUNCTION [dbo].[' + RTRIM(@name) +']'  
   EXEC (@SQL)  
   PRINT 'Dropped Function: ' + @name  
   SELECT @name = (SELECT TOP 1 [name] FROM sysobjects WHERE [type] IN (N'FN', N'IF', N'TF', N'FS', N'FT') AND category = 0 AND [name] > @name ORDER BY [name])  
 END  
 GO
  
 /* Drop all Foreign Key constraints */  

 DECLARE @name VARCHAR(128)  
 DECLARE @constraint VARCHAR(254)  
 DECLARE @SQL VARCHAR(254)  
 SELECT @name = (SELECT TOP 1 TABLE_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE constraint_catalog=DB_NAME() AND CONSTRAINT_TYPE = 'FOREIGN KEY' ORDER BY TABLE_NAME)  
 WHILE @name is not null  
 BEGIN  
   SELECT @constraint = (SELECT TOP 1 CONSTRAINT_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE constraint_catalog=DB_NAME() AND CONSTRAINT_TYPE = 'FOREIGN KEY' AND TABLE_NAME = @name ORDER BY CONSTRAINT_NAME)  
   WHILE @constraint IS NOT NULL  
   BEGIN  
     SELECT @SQL = 'ALTER TABLE [dbo].[' + RTRIM(@name) +'] DROP CONSTRAINT [' + RTRIM(@constraint) +']'  
     EXEC (@SQL)  
     PRINT 'Dropped FK Constraint: ' + @constraint + ' on ' + @name  
     SELECT @constraint = (SELECT TOP 1 CONSTRAINT_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE constraint_catalog=DB_NAME() AND CONSTRAINT_TYPE = 'FOREIGN KEY' AND CONSTRAINT_NAME <> @constraint AND TABLE_NAME = @name ORDER BY CONSTRAINT_NAME)  
   END  
 SELECT @name = (SELECT TOP 1 TABLE_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE constraint_catalog=DB_NAME() AND CONSTRAINT_TYPE = 'FOREIGN KEY' ORDER BY TABLE_NAME)  
 END  
 GO  

 /* Drop all Primary Key constraints */  

 DECLARE @name VARCHAR(128)  
 DECLARE @constraint VARCHAR(254)  
 DECLARE @SQL VARCHAR(254)  
 SELECT @name = (SELECT TOP 1 TABLE_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE constraint_catalog=DB_NAME() AND CONSTRAINT_TYPE = 'PRIMARY KEY' ORDER BY TABLE_NAME)  
 WHILE @name IS NOT NULL  
 BEGIN  
   SELECT @constraint = (SELECT TOP 1 CONSTRAINT_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE constraint_catalog=DB_NAME() AND CONSTRAINT_TYPE = 'PRIMARY KEY' AND TABLE_NAME = @name ORDER BY CONSTRAINT_NAME)  
   WHILE @constraint is not null  
   BEGIN  
     SELECT @SQL = 'ALTER TABLE [dbo].[' + RTRIM(@name) +'] DROP CONSTRAINT [' + RTRIM(@constraint)+']'  
     EXEC (@SQL)  
     PRINT 'Dropped PK Constraint: ' + @constraint + ' on ' + @name  
     SELECT @constraint = (SELECT TOP 1 CONSTRAINT_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE constraint_catalog=DB_NAME() AND CONSTRAINT_TYPE = 'PRIMARY KEY' AND CONSTRAINT_NAME <> @constraint AND TABLE_NAME = @name ORDER BY CONSTRAINT_NAME)  
   END  
 SELECT @name = (SELECT TOP 1 TABLE_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE constraint_catalog=DB_NAME() AND CONSTRAINT_TYPE = 'PRIMARY KEY' ORDER BY TABLE_NAME)  
 END  
 GO  

 /* Drop all tables */  

 DECLARE @name VARCHAR(128)  
 DECLARE @SQL VARCHAR(254)  
 SELECT @name = (SELECT TOP 1 [name] FROM sysobjects WHERE [type] = 'U' AND category = 0 ORDER BY [name])  
 WHILE @name IS NOT NULL  
 BEGIN  
   SELECT @SQL = 'DROP TABLE [dbo].[' + RTRIM(@name) +']'  
   EXEC (@SQL)  
   PRINT 'Dropped Table: ' + @name  
   SELECT @name = (SELECT TOP 1 [name] FROM sysobjects WHERE [type] = 'U' AND category = 0 AND [name] > @name ORDER BY [name])  
 END  
 GO  

How to drop all stored procedures at once in SQL Server database?


 declare @procName varchar(500)  
 declare cur cursor   
 for select [name] from sys.objects where type = 'p'  
 open cur  
 fetch next from cur into @procName  
 while @@fetch_status = 0  
 begin  
   exec('drop procedure ' + @procName)  
   fetch next from cur into @procName  
 end  
 close cur  
 deallocate cur  

Sunday, November 2, 2014

What is the test card credentials for verifying the payment option in EBS TEST mode?


 
 Card No: 4111 -1111 - 1111 - 1111  
 Exp Date: 07/2016  
 CVV: 123  
 Name of the Issuing Bank: EBS  


Note: No other Card number would be accepted by the Gateway in test phase.