SELECT sqltext.TEXT
,req.session_id
,req.status
,req.command
,req.cpu_time
,req.total_elapsed_time
,req.blocking_session_id
,req.percent_complete
,req.estimated_completion_time/1000/60 estimated_completion_time_Min
,start_time
FROM sys.dm_exec_requests req
CROSS APPLY sys.dm_exec_sql_text(sql_handle) AS sqltext
ORDER BY start_time
Author: armannas
How to modify and add column in SQL Server’s table with TSQL
USE Arm_DB Go IF OBJECT_ID('TBL_Persons','U') IS NOT NULL DROP TABLE TBL_Persons CREATE TABLE TBL_Persons ( ID INT IDENTITY PRIMARY KEY ,NAME Char(50) ) GO ALTER TABLE TBL_Persons ADD Lname Nvarchar(70) Go ALTER TABLE TBL_Persons ALTER COLUMN NAME NVARCHAR(50) GO INSERT INTO TBL_Persons(Name,Lname) VALUES ('Arman','Nas') GO SELECT * FROM TBL_Persons
How to save image or any others file type directly from file in SQL Server with binary format
USE Arm_DB GO IF OBJECT_ID('TBL_Image','U') IS NOT NULL DROP TABLE TBL_Image CREATE TABLE TBL_Image ( [ID] INT IDENTITY(1,1) ,[Image] VARBINARY(MAX) CONSTRAINT PK_TBL_Image PRIMARY KEY CLUSTERED (ID) ) Go INSERT INTO TBL_Image(Image) SELECT * FROM OPENROWSET(BULK 'C:\Users\Public\Pictures\Sample Pictures\Koala.JPG',SINGLE_BLOB ) i
How to create Database in SQL Server with TSQL
USE master GO CREATE DATABASE Arm_DB ON ( NAME = Arm_DB_Dat ,FILENAME = 'C:\Arman\Mine\MyBlog\Database\Arm_DB_Dat.MDF' ,SIZE = 20 ,MAXSIZE = 200 ,FILEGROWTH = 8 ) LOG ON ( NAME = Arm_DB_Log ,FILENAME = 'C:\Arman\Mine\MyBlog\Database\Arm_DB_Log.LDF' ,SIZE = 15MB ,MAXSIZE = 125MB ,FILEGROWTH = 5MB ) GO
How can create Array in VB.Net & C# ?
There are different ways that you can create array , here I am going to explain them for you
1.You can supply the array size when you are declaring it , as the following example shows.
[VB.NET]
Dim cargoWeights(10) As Double Dim atmospherePressures(2, 2, 4, 10) As Short Dim inquiriesByYearMonthDay(20)()() As Byte
[C#]
double[] cargoWeights = new double[11]; short[,,,] atmospherePressures = new short[3, 3, 5, 11]; byte[][][] inquiriesByYearMonthDay = new byte[21][][]; 2.You can also use a New clause to supply the size of an array when it’s created, as the following example shows.
[VB.NET]
cargoWeights = New Double(10) {} atmospherePressures = New Short(2, 2, 4, 10) {} inquiriesByYearMonthDay = New Byte(20)()() {}
[C#]
cargoWeights = new double[11]; atmospherePressures = new short[3, 3, 5, 11]; inquiriesByYearMonthDay = new byte[21][][];
What Is SSL (Secure Sockets Layer) ?
In this post I am going to talk about SSL , Each programer specially web Programmer must know about the SSL.
What Is SSL ?
SSL is a security standard that makes a secure connection between Server and Client , for
example web server (website) and a browser; or a mail server and a mail client (e.g., Outlook).
SSL can guarantee that confidential information same as Credit Card Number , Security numbers and any sensitive information to be transmitted securely.
How does it work?
SSL Certificates have two keys: a public and a private key. These keys work together to make a secure and encrypted connection.
You must create a Certificate Signing Request (CSR) on your server. The CSR makes the private key and a CSR data file that you should send it to the SSL Certificate issuer (Certificate Authority or CA). A public key is created by CA to match your private key without compromising the key itself. The private key is not seen by CA.
Caution!
Anyone can create certificate but browsers only trust certificates that are signed by organization which are in the list of trusted CAs.
How to create cookie in VB.Net & C#
Cookie is one of the useful object that can be used in the web application, and you can use it to save user setting on the local computer or device.
Cookie laws have changed with effect from 26th May 2011.On 26th May 2011, new laws came into force in the UK that affect most web sites. If cookies are used in a site, the Privacy and Electronic Communications (EC Directive) (Amendment) Regulations 2011 (UK Regulations) provide that certain information must be given to that site’s visitors and the user must give his or her consent to the placing of the cookies…..For further information please go to the Cookie Law
Private Sub CreateCookies() If Request.Cookies("UserName") Is Nothing Then Dim aCookie As New HttpCookie("UserName") aCookie.Value = "MyUsername" aCookie.Expires = DateTime.Now.AddDays(30) Response.Cookies.Add(aCookie) Else Dim cookie As HttpCookie = HttpContext.Current.Request.Cookies("UserName") cookie.Value = "UserName" cookie.Expires = DateTime.Now.AddDays(30) Response.Cookies.Add(cookie) End If End Sub [C#] private void CreateCookies() { if (Request.Cookies("UserName") == null) { HttpCookie aCookie = new HttpCookie("UserName"); aCookie.Value = "MyUsername"; aCookie.Expires = DateTime.Now.AddDays(30); Response.Cookies.Add(aCookie); } else { HttpCookie cookie = HttpContext.Current.Request.Cookies("UserName"); cookie.Value = "UserName"; cookie.Expires = DateTime.Now.AddDays(30); Response.Cookies.Add(cookie); } }
//
How can Connect to the SQL Server and Run Commands in VB.Net & C# ?
If you have difficulty to connect to the SQL Server, read this post, it can help you to understand the fundamental:
First let me to explain the basic objects:
1.SqlConnection
This objects contains SQL Connection String, other objects use this object to connect to the SQL Server
2.SqlCommand
This object contains SQL Commands that will be run, it can carry SQL commands or Stored procedure name.
3. SqlDataAdapter
If you want to run Commands that return data (records), you should use this object, it can bring data from SQL Server to your application
now we are familiar with the basic objects that we need to connect to the SQL Server, let start to write the function that run the SQL command for us.
[VB.NET]
Private Sub ConnectToSQLServer() Try Dim SqlConnection As New Data.SqlClient.SqlConnection( "Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Diet;Data Source=.\server2008") Dim SQLcommand As New Data.SqlClient.SqlCommand("SELECT * FROM Foods", SqlConnection) Dim SqlDataAdapter As New Data.SqlClient.SqlDataAdapter(SQLcommand) Dim DtResult As New DataTable SqlConnection.Open() SqlDataAdapter.Fill(DtResult) SqlConnection.Close() Catch ex As Exception Throw ex.InnerException End Try End Sub [C#]
private void ConnectToSQLServer() { try { System.Data.SqlClient.SqlConnection SqlConnection = new System.Data.SqlClient.SqlConnection ("Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Diet;Data Source=.\\server2008"); System.Data.SqlClient.SqlCommand SQLcommand = new System.Data.SqlClient.SqlCommand("SELECT * FROM Foods", SqlConnection); System.Data.SqlClient.SqlDataAdapter SqlDataAdapter = new System.Data.SqlClient.SqlDataAdapter(SQLcommand); DataTable DtResult = new DataTable(); SqlConnection.Open(); SqlDataAdapter.Fill(DtResult); SqlConnection.Close(); } catch (Exception ex) { throw ex.InnerException; } }
