Sunday, December 15, 2013

Saving changes is not permitted. The changes you have made require the following tables to be dropped and recreated...

Hi Friends,

If you see this error while you trying to save your table changes in sql server design mode,



 Follow the below steps to solve this issue.

Go to menu "Tools--> Options"
Select "Designers"
Uncheck the check box "Prevent saving changes that require table re-creation".

 
Thank you
 

Friday, December 9, 2011

XSLT - Numeric Checking

Hi Friends,

Here I would like to say about XSLT programming.
The example mentioned below is for finding the numeric values contained in an xml file.

For testing this example you need two files.

1. XML file its name should be "Numbers.xml"
2. XSL file its name should be "NumberCheck.xsl"

Copy these files to a folder and open the xml file in a browser.

"Numbers.xml"
---------------------
<?xml version="1.0" ?>
<?xml-stylesheet type="text/xsl" href="NumberCheck.xsl" ?>
<Numbers>
<Number>
<Value>11</Value>
</Number>
<Number>
<Value>12</Value>
</Number>
<Number>
<Value>DD</Value>
</Number>
<Number>
<Value>23</Value>
</Number>
<Number>
<Value>33</Value>
</Number>
<Number>
<Value>FF</Value>
</Number>
<Number>
<Value>VV</Value>
</Number>
</Numbers>

"NumberCheck.xsl"
---------------------------
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="Numbers">
<TABLE>
<xsl:for-each select="Number">
<xsl:choose>
<xsl:when test='number(Value)'>
<TR>
<TD>
I am a numeric value : <xsl:value-of select="Value" />
</TD>
</TR>
</xsl:when>
<xsl:otherwise>
<TR>
<TD>
I am not a numeric value : <xsl:value-of select="Value" />
</TD>
</TR>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</TABLE>
</xsl:template>
</xsl:stylesheet>

In this example the xslt function <xsl:when test='number(Value)'> will help you to find the given value is a numeric or not

its out put will be like this

I am a numeric value : 11
I am a numeric value : 12
I am not a numeric value : DD
I am a numeric value : 23
I am a numeric value : 33
I am not a numeric value : FF
I am not a numeric value : VV

Wednesday, October 12, 2011

SQL Query for selecting database objects

1. SQL Query for selecting database objects

SELECT * FROM SYS.OBJECTS

2. SQL Query for selecting database Stored Procedurers

SELECT * FROM SYS.OBJECTS WHERE TYPE = 'P' ORDER BY NAME ASC

3. SQL Query for selecting database Tables

SELECT * FROM SYS.OBJECTS WHERE TYPE = 'U' ORDER BY NAME ASC

4.SQL Query for selecting database Functions

SELECT * FROM SYS.OBJECTS WHERE TYPE = 'FN' ORDER BY NAME ASC

5.SQL Query for selecting database Primary Keys

SELECT * FROM SYS.OBJECTS WHERE TYPE = 'PK' ORDER BY NAME ASC

Thursday, May 19, 2011

Play a video file in HTML

<object classid='CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95' id='player' width='150'
height='150' standby='Please wait while the object is loaded...'>
<param name='url' value='D:\Experiments\clock.avi' />
<param name='src' value='D:\Experiments\clock.avi' />
<param name='AutoStart' value='false' />
<param name='Balance' value='0' /> //-100 is fully left, 100 is fully right.
<param name='CurrentPosition' value='0' /> //Position in seconds when starting.
<param name='showcontrols' value='true' /> //Show play/stop/pause controls.
<param name='enablecontextmenu' value='true' /> //Allow right-click.
<param name='fullscreen' value='true' /> //Start in full screen or not.
<param name='mute' value='false' />
<param name='PlayCount' value='1' /> //Number of times the content will play.
<param name='rate' value='1.0' /> //0.5=Slow, 1.0=Normal, 2.0=Fast
<param name='uimode' value='custom' /> // full, mini, custom, none, invisible
<param name='showdisplay' value='false' /> //Show or hide the name of the file.
<param name='volume' value='50' /> // 0=lowest, 100=highest
</object>

Tuesday, May 10, 2011

SQL Bulk Copy

SQL Bulk Copy is for moving data from one Table to another. This can be from a single server or between different servers (Source and destination are different servers).
SqlBulk copy class can be used to write data only to sql server tables. Any data source can be used for loading data as long as the data can be loaded to a Data Table or read with an IDataReader instance.
In The example mentioned below, I am using Oracle Table as source and Sql Server Table as destination. Also DataReader is using to fetch data from oracle.

SQL Bulk Copy Example

public void BulkCopyMethod()
{
string oracleConnectionString = "Data Source=SERVICENAME;User Id=USERNAME;Password=PASSWORD;";
string sqlConnectionString = "Data Source=DATASOURCE;Initial Catalog=DATABASENAME;Connect Timeout=0;User ID=USERNAME;Pwd=PASSWORD;";
string oracleSelectStatement = "SELECT EmployeeID,EmployeeName,EmployeeAge,EmployeePlace,EmployeePin,EmployeePhoneNum FROM EmployeeData";

using (OracleConnection oracleConn = new OracleConnection(oracleConnectionString))
{
oracleConn.Open();
OracleCommand employeeCommand = new OracleCommand(oracleSelectStatement, oracleConn);
OracleDataReader employeeReader = employeeCommand.ExecuteReader();

using (SqlBulkCopy bulkCopy = new SqlBulkCopy(sqlConnectionString))
{
bulkCopy.DestinationTableName = "dbo.tblEmployee";
bulkCopy.ColumnMappings.Add("EmployeeID", "Id");
bulkCopy.ColumnMappings.Add("EmployeeName", "Emp_Name");
bulkCopy.ColumnMappings.Add("EmployeeAge", "Emp_Age");
bulkCopy.ColumnMappings.Add("EmployeePlace", "Emp_Place");
bulkCopy.ColumnMappings.Add("EmployeePin", "Emp_Pin");
bulkCopy.ColumnMappings.Add("EmployeePhoneNum", "Emp_Phone");

try
{
bulkCopy.WriteToServer(employeeReader);
}
catch (Exception ex)
{
throw ex;
}
finally
{
bulkCopy.Close();
employeeReader.Close();
employeeCommand.Dispose();
oracleConn.Close();
}
}
}
}

For more info:- http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlbulkcopy.aspx

Monday, April 25, 2011

How to Serialize and DeSerialize a Generic List

private void button1_Click(object sender, EventArgs e)
{
List<Employee> emps = new List<Employee>();
emps.Add(new Employee("1", "Sabu"));
emps.Add(new Employee("2", "John"));
emps.Add(new Employee("3", "Tom"));
emps.Add(new Employee("4", "George"));
string serializedXmlString = XmlSerialize(emps);
List<Employee> deserializedEmps = XmlDeserialize(serializedXmlString);
}

//XmlSerialize method
public string XmlSerialize(List<Employee> emps)
{
System.Xml.Serialization.XmlSerializer xmlSer = new System.Xml.Serialization.XmlSerializer(emps.GetType());
StringWriter textWriter = new StringWriter();
xmlSer.Serialize(textWriter, emps);
xmlSer = null;
return textWriter.ToString();
}


//XmlDeserialize method
public List<Employee> XmlDeserialize(String data)
{
System.Xml.Serialization.XmlSerializer xmlSer = new System.Xml.Serialization.XmlSerializer(typeof(List<Employee>));
TextReader reader = new StringReader(data);
object obj = xmlSer.Deserialize(reader);
return (List<Employee>)obj;
}


//Employee Class with Serializable attribute

[Serializable]
public class Employee
{
public Employee()
{
ID = "";
Name = "";
}

public Employee(String id, String name)
{
ID = id;
Name = name;
}


public string ID { get; set; }
public string Name { get; set; }
}

SQL Table Reseeding

For Reseeding an Identity column use this statement.

DBCC CHECKIDENT (Employee, RESEED, 0)
Employee is the TABLE NAME. After the execution of this statement identity value will start from 1...

if you want to start from 11, execute statement like
DBCC CHECKIDENT (Employee, RESEED, 10)


DBCC means Database Console Commands.
this command statements are grouped in to several categories

  • Maintenance statements - Maintenance tasks on a database, index, or filegroup.
  • Miscellaneous statements - Miscellaneous tasks such as enabling row-level locking or removing a dynamic-link library (DLL) from memory.
  • Status statements - Status checks.
  • Validation statements - Validation operations on a database, table, index, catalog, filegroup, system tables, or allocation of database pages.

For more info
1. http://msdn.microsoft.com/en-us/library/aa258281(v=sql.80).aspx
2. http://msdn.microsoft.com/en-us/library/aa258817(v=sql.80).aspx