Preventing the Drop and Alter table in Sql Server Using DDL Trigger
In the following example, DDL trigger safety will fire whenever a DROP_TABLE or ALTER_TABLE
event occurs in the database.
CREATE TRIGGER safety
ON DATABASE
FOR DROP_TABLE, ALTER_TABLE
AS
PRINT 'You must disable Trigger "safety" to drop or alter tables!'
ROLLBACK
;
Dotnet, DotnetCore, Azure, C#,VB.net, Sql Server, WCF, MVC ,Linq, Javascript and Jquery
21 April 2011
Difference between sp_executesql and EXEC() in Sql Server
Difference between sp_executesql and EXEC() in Sql Server
EXEC() - whose first parameter is a parameterized SQL statement.
sp_executesql - The second parameter is a parameter-list declaration, similar to the parameter
list present in the declaration of a stored procedure.
If the malicious user enters a value as Sql Injection EXEC() execute the maliculous code
but sp_executesql It will search for the value ' or '1'='1 as product name in the database.
Thus preventing SQL Injection attacks.
EXEC() - whose first parameter is a parameterized SQL statement.
sp_executesql - The second parameter is a parameter-list declaration, similar to the parameter
list present in the declaration of a stored procedure.
If the malicious user enters a value as Sql Injection EXEC() execute the maliculous code
but sp_executesql It will search for the value ' or '1'='1 as product name in the database.
Thus preventing SQL Injection attacks.
16 April 2011
Connection String For dotnet framework Vb.net and C# Connectivity
Connection String For dotnet framework
Vb.net Connectivity
'VB
Dim connection as DbConnection = new SqlConnection()
connection.ConnectionString = _
"Server=.;Database=pubs;Trusted_Connection=true" connection.Open()
'Do lots of cool work here
connection.Close()
C# Connectivity
//C#
DbConnection connection = new SqlConnection();connection.ConnectionString =
"Server=.;Database=pubs;Trusted_Connection=true"; connection.Open();
//Do lots of cool work here connection.Close();
Creating an instance of the SqlConnection class using the SQL Server .NET provider creates
the DbConnection. The ConnectionString property is initialized to use the local machine (".")
and the database is set to pubs. Lastly, the connection uses a trusted connection for
authentication when connecting to SQL Server.
Vb.net Connectivity
'VB
Dim connection as DbConnection = new SqlConnection()
connection.ConnectionString = _
"Server=.;Database=pubs;Trusted_Connection=true" connection.Open()
'Do lots of cool work here
connection.Close()
C# Connectivity
//C#
DbConnection connection = new SqlConnection();connection.ConnectionString =
"Server=.;Database=pubs;Trusted_Connection=true"; connection.Open();
//Do lots of cool work here connection.Close();
Creating an instance of the SqlConnection class using the SQL Server .NET provider creates
the DbConnection. The ConnectionString property is initialized to use the local machine (".")
and the database is set to pubs. Lastly, the connection uses a trusted connection for
authentication when connecting to SQL Server.
Difference between typed dataset and untyped dataset in .Net framework
Difference between typed dataset and untyped dataset in .Net framework
Datasets can be typed or untyped.
A typed dataset is a dataset that is first derived from the base DataSet class and then uses information in an XML Schema file (an .xsd file) to generate a new class. Information from the schema (tables, columns, and so on) is generated and compiled into this new dataset class as a set of first-class objects and properties.
An untyped dataset, in contrast, has no corresponding built-in schema. As in a typed dataset,
an untyped dataset contains tables, columns, and so on — but those are exposed only as collections.
Typed DataSet
// C#
// This accesses the CustomerID column in the first row of
// the Customers table.
string s;
s = dsCustomersOrders1.Customers[0].CustomerID;
Untyped Datasets
// C#
string s = (string) dsCustomersOrders1.Tables["Customers"].Rows[0]["CustomerID"];
In addition to being easier to work with, the syntax for the typed dataset provides type checking at compile time, greatly reducing the possibility of errors in assigning values to dataset members.
Datasets can be typed or untyped.
A typed dataset is a dataset that is first derived from the base DataSet class and then uses information in an XML Schema file (an .xsd file) to generate a new class. Information from the schema (tables, columns, and so on) is generated and compiled into this new dataset class as a set of first-class objects and properties.
An untyped dataset, in contrast, has no corresponding built-in schema. As in a typed dataset,
an untyped dataset contains tables, columns, and so on — but those are exposed only as collections.
Typed DataSet
// C#
// This accesses the CustomerID column in the first row of
// the Customers table.
string s;
s = dsCustomersOrders1.Customers[0].CustomerID;
Untyped Datasets
// C#
string s = (string) dsCustomersOrders1.Tables["Customers"].Rows[0]["CustomerID"];
In addition to being easier to work with, the syntax for the typed dataset provides type checking at compile time, greatly reducing the possibility of errors in assigning values to dataset members.
Generics in .Net Framework
Generics in .Net Framework
Used to Reduced run-time errors,The compiler cannot detect type errors when you cast
to and from the Object class.the runtime will throw an exception
Using generics allows the compiler to catch this type of bug before your program runs
Generics improves runtime Performance.
Eg:
// Add a double and an int using the Obj class
Obj ob = new Obj(10.125, 2005);
Console.WriteLine((double)ob.t + (int)ob.u);
// Add a double and an int using the Gen class
Gen gb = new Gen(10.125, 2005);
Console.WriteLine(gb.t + gb.u);
If you run that code in a console application, the Obj and Gen classes produce exactly
the same results. However, the code that uses the Gen class actually works faster
because it does not require boxing and unboxing to and from the Object class.
Used to Reduced run-time errors,The compiler cannot detect type errors when you cast
to and from the Object class.the runtime will throw an exception
Using generics allows the compiler to catch this type of bug before your program runs
Generics improves runtime Performance.
Eg:
// Add a double and an int using the Obj class
Obj ob = new Obj(10.125, 2005);
Console.WriteLine((double)ob.t + (int)ob.u);
// Add a double and an int using the Gen class
Gen
Console.WriteLine(gb.t + gb.u);
If you run that code in a console application, the Obj and Gen classes produce exactly
the same results. However, the code that uses the Gen class actually works faster
because it does not require boxing and unboxing to and from the Object class.
Commonly used interfaces in .Net
Commonly used interfaces
Class Description
IComparable
-----------
Implemented by types whose values can be ordered; for example, the numeric and string classes. IComparable is required for sorting.
IDisposable
-----------
Defines methods for manually disposing of an object. This interface is important for large objects that consume resources, or objects that lock access to resources such as databases.
IConvertible
------------
Enables a class to be converted to a base type such as Boolean,Byte, Double, or String.
ICloneable
----------
Supports copying an object.
IEquatable
----------
Allows you to compare to instances of a class for equality. For example, if you implement this interface, you could say “if (a == b)”.
IFormattable
------------
Enables you to convert the value of an object into a specially formatted string. This provides greater flexibility than the base ToString method.
Class Description
IComparable
-----------
Implemented by types whose values can be ordered; for example, the numeric and string classes. IComparable is required for sorting.
IDisposable
-----------
Defines methods for manually disposing of an object. This interface is important for large objects that consume resources, or objects that lock access to resources such as databases.
IConvertible
------------
Enables a class to be converted to a base type such as Boolean,Byte, Double, or String.
ICloneable
----------
Supports copying an object.
IEquatable
----------
Allows you to compare to instances of a class for equality. For example, if you implement this interface, you could say “if (a == b)”.
IFormattable
------------
Enables you to convert the value of an object into a specially formatted string. This provides greater flexibility than the base ToString method.
15 April 2011
Disable remember password option in Firefox/Internet Explorer In Code
Disable remember password option in Firefox/Internet Explorer In Code
For Disable remember password option in Firefox/Internet Explorer In Form
<form id="loginForm" autocomplete="off">
</form>
For Disable remember password option in Firefox/Internet Explorer In Particular Controls
<asp:TextBox ID="TextBox1" autocomplete="off" runat="server" TextMode="Password">
For Disable remember password option in Firefox/Internet Explorer In Form
<form id="loginForm" autocomplete="off">
</form>
For Disable remember password option in Firefox/Internet Explorer In Particular Controls
<asp:TextBox ID="TextBox1" autocomplete="off" runat="server" TextMode="Password">
Subscribe to:
Posts (Atom)
Implementing OAuth validation in a Web API
I mplementing OAuth validation in a Web API Implementing OAuth validation in a Web API using C# typically involves several key steps to sec...
-
ViewBag, ViewData, TempData and View State in MVC ASP.NET MVC offers us three options ViewData, ViewBag and TempData for passing data from...
-
// Export Datatable to Excel in C# Windows application using System; using System.Data; using System.IO; using System.Windows.Forms; ...