Tuesday, December 22, 2015

How do I reset a sequence in sql

ALTER SEQUENCE Schema.SequenceName
RESTART WITH 1

Identity jump issue in sql server


  1. Open "SQL Server Configuration Manager"
  2. Click "SQL Server Services" on the left pane 
  3. Right-click on your SQL Server instance name on the right pane ->Default: SQL Server(MSSQLSERVER)
  4. Click "Properties"
  5. Click "Startup Parameters"
  6. On the "specify a startup parameter" textbox type "-T272" 
  7. Click "Add" 
  8. Confirm the changes

Monday, November 16, 2015

Set the width of select2 input

$("select").select2({ width: 'resolve' });
OR
$("select").select2({ width: '100%' });
OR
$("select").select2({ dropdownAutoWidth : true });

Thursday, November 12, 2015

Determine Whether a Table Has an Identity Column

SQL Server 2005+

SELECT OBJECTPROPERTY(object_id('TableToBeChecked'), 'TableHasIdentity')

SMO

Server srv = new Server("(local)");
Database db = srv.Databases["AdventureWorks2012"];

Table tb = new Table(db, "Test Table");
Column col1 = new Column(tb, "TableIdentifier", DataType.Int);
col1.Identity = true;
tb.Columns.Add(col1); 
try
{
foreach (String s in tb.CheckIdentityValue())
{
   Console.WriteLine(s);
}
}
catch
{
}

Wednesday, October 28, 2015

How to find a column in all tables sql server

SELECT t.name AS table_name,
SCHEMA_NAME(schema_id) AS schema_name,
c.name AS column_name
FROM sys.tables AS t
INNER JOIN sys.columns c ON t.OBJECT_ID = c.OBJECT_ID
WHERE c.name LIKE 'BranchId'
ORDER BY schema_name, table_name;

Saturday, October 10, 2015

bobj is not defined crystal report

Make sure aspnet_client folder is present in the root of your application with the appropriate version of asp net framework
for dot net 4.0, 4.5.* use folder aspnet_client\system_web\4_0_30319\crystalreportviewers13
for dot net 4.6 use folder aspnet_client\system_web\4_6_81\crystalreportviewers13

Saturday, October 3, 2015

Variable table name ms sql server

no allowed use dynamic sql instead.

build dynamic sql and then use exec or sp_executesql to run query

EXEC | EXECUTE

Example
DECLARE @table VARCHAR(50) = 'HR.Employees';
EXEC ( 'SELECT * FROM '+@table );

Example 2 [Stored Procedure]
DECLARE @ID INT = 34;
EXEC ( '[dbo].[p__Clean] '''+@ID+'''' );

Friday, October 2, 2015

How to determine the number of days in a month in SQL Server?

CREATE FUNCTION dbo.f__GetDaysInMonth(
                @Date DATE )
RETURNS TINYINT
AS
BEGIN
     DECLARE @Days TINYINT;
     SELECT @Days = DAY(DATEADD(month, DATEDIFF(MONTH, 0, @Date) + 1, -1));
 RETURN @Days
END;
GO
--Usage
SELECT dbo.f__GetDaysInMonth('11-Apr-2015')

Sunday, September 27, 2015

There are uncommitted transactions. Do you wish to commit these before closing the window?

This happens when ANSI_DEFAULTS is set ON

which enables

SET ANSI_NULLS
SET CURSOR_CLOSE_ON_COMMIT
SET ANSI_NULL_DFLT_ON
SET IMPLICIT_TRANSACTIONS 
SET ANSI_PADDING
SET QUOTED_IDENTIFIER
SET ANSI_WARNINGS

and because of IMPLICIT_TRANSACTIONS transactions that are automatically opened as the result of this setting being ON must be explicitly committed or rolled back by the user at the end of the transaction

so you have to select commit and execute

List of known project type Guids visual studio

C#{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
VB.NET{F184B08F-C81C-45F6-A57F-5ABD9991F28F}
C++{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}
F#{F2A71F9B-5D33-465A-A702-920D77279786}
J#{E6FDF86B-F3D1-11D4-8576-0002A516ECE8}
JScript{262852C6-CD72-467D-83FE-5EEB1973A190}
Web Application{349C5851-65DF-11DA-9384-00065B846F21}
Web Site{E24C65DC-7377-472B-9ABA-BC803B73C61A}
Distributed System{F135691A-BF7E-435D-8960-F99683D2D49C}
Windows Communication Foundation (WCF){3D9AD99F-2412-4246-B90B-4EAA41C64699}
Windows Presentation Foundation (WPF){60DC8134-EBA5-43B8-BCC9-BB4BC16C2548}
Visual Database Tools{C252FEB5-A946-4202-B1D4-9916A0590387}
Database{A9ACE9BB-CECE-4E62-9AA4-C7E7C5BD2124}
Database (other project types){4F174C21-8C12-11D0-8340-0000F80270F8}
Test{3AC096D0-A1C2-E12C-1390-A8335801FDAB}
Legacy (2003) Smart Device (C#){20D4826A-C6FA-45DB-90F4-C717570B9F32}
Legacy (2003) Smart Device (VB.NET){CB4CE8C6-1BDB-4DC7-A4D3-65A1999772F8}
Smart Device (C#){4D628B5B-2FBC-4AA6-8C16-197242AEB884}
Smart Device (VB.NET){68B1623D-7FB9-47D8-8664-7ECEA3297D4F}
Workflow (C#){14822709-B5A1-4724-98CA-57A101D1B079}
Workflow (VB.NET){D59BE175-2ED0-4C54-BE3D-CDAA9F3214C8}
Deployment Merge Module{06A35CCD-C46D-44D5-987B-CF40FF872267}
Deployment Cab{3EA9E505-35AC-4774-B492-AD1749C4943A}
Deployment Setup{978C614F-708E-4E1A-B201-565925725DBA}
Deployment Smart Device Cab{AB322303-2255-48EF-A496-5904EB18DA55}
Visual Studio Tools for Applications (VSTA){A860303F-1F3F-4691-B57E-529FC101A107}
Visual Studio Tools for Office (VSTO){BAA0C2D2-18E2-41B9-852F-F413020CAA33}
SharePoint Workflow{F8810EC1-6754-47FC-A15F-DFABD2E3FA90}
XNA (Windows){6D335F3A-9D43-41b4-9D22-F6F17C4BE596}
XNA (XBox){2DF5C3F4-5A5F-47a9-8E94-23B4456F55E2}
XNA (Zune){D399B71A-8929-442a-A9AC-8BEC78BB2433}
SharePoint (VB.NET){EC05E597-79D4-47f3-ADA0-324C4F7C7484}
SharePoint (C#){593B0543-81F6-4436-BA1E-4747859CAAE2}
Silverlight{A1591282-1198-4647-A2B1-27E5FF5F6F3B}
ASP.NET MVC 1.0{603C0E0B-DB56-11DC-BE95-000D561079B0}
ASP.NET MVC 2.0{F85E285D-A4E0-4152-9332-AB1D724D3325}
ASP.NET MVC 3.0{E53F8FEA-EAE0-44A6-8774-FFD645390401}
ASP.NET MVC 4.0{E3E379DF-F4C6-4180-9B81-6769533ABE47}
Extensibility{82B43B9B-A64C-4715-B499-D71E9CA2BD60}
Store App Windows Phone 8.1{76F1466A-8B6D-4E39-A767-685A06062A39}
Store App Windows Phone 8.1 Silverlight (C#){C089C8C0-30E0-4E22-80C0-CE093F111A43}
Store App Windows Phone 8.1 Silverlight (VB.NET){DB03555F-0C8B-43BE-9FF9-57896B3C5E56}
Store App Windows 8.1{BC8A1FFA-BEE3-4634-8014-F334798102B3}
Store App Universal{D954291E-2A0B-460D-934E-DC6B0785DB48}
Store App Portable Universal{786C830F-07A1-408B-BD7F-6EE04809D6DB}
LightSwitch{8BB0C5E8-0616-4F60-8E55-A43933E57E9C}
LightSwitch Project{581633EB-B896-402F-8E60-36F3DA191C85}
Office/SharePoint App{C1CDDADD-2546-481F-9697-4EA41081F2FC}

Controlling order of serialization in asp net c#

use Order with XmlElement
public class ItemGroup
{
    [XmlElement(Order = 0)]
    public Reference Reference { getset; }
    [XmlElement(Order = 1)]
    public Reference None { getset; }
    [XmlElement(Order = 2)]
    public Reference Content { getset; }
    [XmlElement(Order = 3)]
    public Reference Compile { getset; }
}

The OutputPath property is not set for this project. Please check to make sure that you have specified a valid Configuration/Platform combination

Problem 1

when the OutputPath property of the project file(*.csproj) is blank.

Solution

Provide OutputPath property which normally is \bin\debug or \bin\release


Problem 3

When the OutputPath comes after Import declaration


Solution

Move Imports after all PropertyGroup declarations


A namespace does not directly contain members such as fields or methods

Change the Build Action to None

Saturday, September 26, 2015

How to serialize an object to XML without getting xsi and xsd

To remove namespaces all together

just add

var ns = new XmlSerializerNamespaces();
ns.Add("""");
and then

var xmlSerializer = new XmlSerializer(typeof(Project));

xmlSerializer.Serialize(fs, project, ns);

but if you want to keep xmlns only with xsi and xsd you should add default namespace to XmlSerializer like this

var defaultNamespace = "http://schemas.microsoft.com/developer/msbuild/003";
var xmlSerializer = new XmlSerializer(typeof(Project), defaultNamespace);
 
xmlSerializer.Serialize(fs, project, ns);

Saturday, September 19, 2015

Repeat row value in Cross-Tab crystal report

Create a new formula field.
In this formula field, joint all selected column i.e. column1 & column2 & column3. This will create a field which has all distinct values and include this field in your cross tab before the non repeating column.Now all required values will repeat in each row as you like.
Regards

Tuesday, September 8, 2015

What .NET version are you running (2.0, 4.5, 4.5.1 or 4.5.2)

From .NET 2.0 to 3.5

Right click on C:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorwks.dll and choose properties
Go to Details tab and look at file version

.NET 4.0, 4.5, 4.5.1 and 4.5.2

Right click on C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll and choose properties
Go to Details tab and look at file version

Monday, July 13, 2015

How to get sql server bak file logical name

RESTORE FILELISTONLY 
FROM  DISK = N'path to bak file' 
WITH  FILE = 1 
GO

Use WITH MOVE to identify a valid location for the file.

USE [master]
GO
RESTORE DATABASE [DBName] 
FROM  DISK = N'Path to BAK File' 
WITH  FILE = 1,  
MOVE N'Logical File Name' TO N'New Path to mdf file',  
MOVE N'Logical File Log Name' TO N'New Path to log file',  
NOUNLOAD,  REPLACE,  STATS = 1
GO


To get logical file list

RESTORE FILELISTONLY 
FROM  DISK = N'path to bak file' 
WITH  FILE = 1 
GO

Sunday, June 14, 2015

crystal report for visual studio 2015 / dot net framework 4.6

just copy existing framework folder in aspnet_client\system_web folder and the rename it to 4_81 or whatever version you have installed and your are done
To Check your version click here
http://w3dproblems.dcense.com/2015/09/what-net-version-are-you-running-20-45.html

Sunday, May 24, 2015

Visual Studio 2012, 2013, 2015 and ASP.NET Web Configuration Tool

Run this command in console(cmd)
"C:\Program Files\IIS Express\iisexpress.exe" /path:c:\windows\Microsoft.NET\Framework\v4.0.30319\ASP.NETWebAdminFiles /vpath:"/asp.netwebadminfiles" /port:8089 /clr:4.0 /ntlm
Than open your browser and open this url http://localhost:8089/asp.netwebadminfiles/default.aspx?applicationPhysicalPath=[Exact_Project_Path]\&applicationUrl=/ 
Also make sure you have this connection string in your web.config file
<connectionStrings>
    <clear/>
    <add name="LocalSQLServer" connectionString="......." providerName="System.Data.SqlClient"/>
  </connectionStrings>
<clear> is important

Tuesday, May 19, 2015

LINQ: SqlDateTime overflow. Must be between ...

WHEN a NULL value to passed to a non null datetime field using LINQ datasource. If the field is autogenerated make sure to mark as autogenerated in LINQ DBML designer else pass the value using a parameter

Thursday, May 14, 2015

Get all asp net listview items in array

var rows = [];
$('#<%: lvStudents.ClientID %>_itemPlaceholderContainer tr:gt(1)').each(function (i, v) {
    var row = $(this);
    rows.push(row);
});
if InsertItemPosition="LastItem"
gt(1)
else if InsertItemPosition="FirstItem" 
gt(2)

Skip first N elements in JQuery

jQuery has a gt selector. (Greater than).
$('#test > div:gt(1)');
Or you can use the slice function
$('#test > div').slice(2);

Wednesday, May 13, 2015

How to update rows randomly

update dbo.Table 
set Field = Value 
where Id in ( select top 50 percent id from dbo.Table order by NEWID() )

Handling Multiple FULL OUTER JOIN in sql

SELECT A.column2 , B.column2 , C.column2 FROM ( 
 (SELECT month, column2 FROM table1) 

 FULL OUTER JOIN 
 (SELECT month, column2 FROM table2) 
B on A.month= B.month 
 FULL OUTER JOIN 
 (SELECT month, column2 FROM table3) 
C on ISNULL(A.month, B.month) = C.month )

How to update rows with a random date

UPDATE table SET datetimecol = DATEADD(day, (ABS(CHECKSUM(NEWID())) % 65530), 0)

How to convert IList to IQuerable

IQueryable query = new List() { 1, 2, 3, 4, 5}.AsQueryable();

How to check if IQueryable result set is null or empty

list will never be null with LINQ; it will simply represent an "empty collection" if need be. The way to test is with the Any extension method:
if (list.Any()) 
{
// list has at least one item
}

What “exec sp_reset_connection” shown in Sql Profiler means?

sp_reset_connection indicates that connection pool is being reused

Saturday, May 9, 2015

Disabling Chrome, Firefox, Safari, Opera, IE Autofill

<form>
<!-- fake fields are a workaround for chrome autofill getting the wrong fields -->
<input style="displaynone" type="text" name="fakeusernameremembered" />
<input style="displaynone" type="password" name="fakepasswordremembered" />
</form>

Friday, May 8, 2015

Value cannot be null. Parameter name: panelsCreated[0] asp net

Switch scriptmanager mode to release

<asp:ScriptManager runat="server" ScriptMode="Release" />

InvalidOperationException: Could not find UpdatePanel with ID asp net

Change ClientIDMode on UpdatePanels to AutoID

<asp:UpdatePanel runat="server" ClientIDMode="AutoID">

Monday, May 4, 2015

Friday, May 1, 2015

How to disable/enable buttons and links (jQuery + Bootstrap)

jQuery.fn.extend({
   disable: function (state) {
      return this.each(function () {
         var $this = jQuery(this);
         if ($this.is('input, button'))
            this.disabled = state;
         else if($this.is('a'))
            $this.toggleClass('disabled', state);
      });
   }
});

Thursday, April 30, 2015

Monday, April 20, 2015

Using DataBinder.Eval in the RowDataBound Event asp net gridview

decimal totalAmount = 0;
protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
 totalAmount += Decimal.Parse(DataBinder.Eval(e.Row.DataItem, "Amount").ToString());
}
}

Sunday, April 19, 2015

Cannot generate deployment plan SSDT

Delete the .dbmdl file in your database project.

Getting relative virtual path from physical path asp net c#

var relativePath = "/" + physicalPath.Replace(HttpContext.Current.Request.PhysicalApplicationPath, String.Empty).Replace("\\""/");
Or use the extension method
/// <summary>
/// Get relative path from physical path
/// </summary>
/// <param name="di">DirectoryInfo</param>
/// <returns></returns>
public static string GetRelativePath(this DirectoryInfo di)
{
 return "/" + di.FullName.Replace(HttpContext.Current.Request.PhysicalApplicationPath, String.Empty).Replace("\\""/");
}

Wednesday, April 15, 2015

How to add serial no in crystal report cross tab

No option in crystal report instead use sql server's DENSE RANK FUNCTION
e.g.
SELECT DENSE_RANK() OVER(ORDER BY g.[FirstColumnInCrossTab]) SrNo, * FROM 

Monday, April 13, 2015

How do I convert an enum to a list in asp net C#

Enum.GetValues(typeof(SomeEnum)).Cast<SomeEnum>().Select(v => v.ToString()).ToList();

Monday, March 23, 2015

PayPal “The Operation has timed out” with specific Credit Card

4111111111111111 wont work.

Name: Any Name
Card Number
You can use the below test cards 
  1. 4446283288032978
  2. 4446283288034636
  3. 4446283288031707
  4. 4446283288033059
Card Type: visa
Expiration Date: Any Future Date
Security Code: any 3 digits

How to allow download of .json file with ASP.NET

Add
<staticContent>
    <mimeMap fileExtension=".json" mimeType="application/json" />
</staticContent>
to web.config system.webServer section

Tuesday, March 10, 2015

Friday, January 23, 2015

Friday, January 2, 2015

Enabling CLR Integration on SQL Server

EXEC sp_CONFIGURE 'show advanced options' , '1';
GO
RECONFIGURE WITH OVERRIDE
GO
 
EXEC sp_CONFIGURE 'clr enabled' , '1'
GO
RECONFIGURE WITH OVERRIDE
GO
If you use with override option, then restart is not required.

Crystal Report: Pad a number with leading zeros up to a fixed length

If table.field is a number

ToText({table.field},"00000000")

or

if is a string


Right("0000"&{MyFieldToPad},8)