Using cookieless sessionState in ASP.Net

If your ASP.Net application is storing sessionState data and you want to avoid using cookies, this can be achieved by simply setting the sessionState cookieless parameter to “true”. This will create a unique id for the sessionState and ammend any application URLs by adding this id to them.

For example, if the URL of your application homepage normally looks like this

http://localhost/myapplication/default.aspx

Cookieless sessionState would ammend the URL to read:

http://localhost/myapplication/(S(somerandomID))/default.aspx

Setting this up is simple. It is merely a case of changing the cookieless value of the sessionState entry in the Web.config file of your application, like so:

<system.web>
     <sessionState mode="InProc" timeout="60" cookieless="true" />
</system.web>

The example above uses the InProcess sessionState mode (which ASP uses by default for performance), sets a session timeout of 60 minutes and enables cookieless sessionState. The beauty of this built in feature means that ASP.Net handles all sessionState cookieless features for you. All URLs in your application will be ammended with this sessionState ticket and sent with the queryString at every postback to the server – no other coding is required.

Please note that the state will be lost if the user url-rewrites any of the links within your application, but so long as the user keeps to the links within your site then state will be maintained and any data you have stored in the way of session variables, for example, will be available to the application.

Posted in ASP.Net, Web Development | Tagged , , , | Comments Off

Populating an ASP.Net drop down list using LINQ to SQL with C#

This example shows how to populate an ASP.Net drop down list control using LINQ to SQL with C#.  This example uses a stored procedure called from within the code behind  of the ASP.Net page. A sample method passes in a user ID which is then passed to the stored procedure.

Once you have created the datacontext diagram for your application, simply create an instance of it and populate the control as so:

protected void sampleMethod(int userId)
{
     using (var dc = new MyApplicationDataContext())
     {
          ddlMyDropDownList.DataSource = dc.SP_myStoredProc(userId);
          ddlMyDropDownList.DataTextField = "USER_NAME";
          ddlMyDropDownList.DataValueField = "USER_ID";
          ddlMyDropDownList.DataBind();
     }
}

You can also add an inline value to be shown in the drop down list and insert it at any point in the list at runtime, like so:

protected void sampleMethod(int userId)
{
     using (var dc = new MyApplicationDataContext())
     {
          ddlMyDropDownList.DataSource = dc.SP_myStoredProc(userId);
          ddlMyDropDownList.DataTextField = "USER_NAME";
          ddlMyDropDownList.DataValueField = "USER_ID";
          ddlMyDropDownList.DataBind();
          ListItem li = new ListItem("Inline Value", "78");
          ddlMyDropDownList.Items.Insert(0, li);
     }
}

The above code creates a list item and assigns some text and a value to it. The last line then inserts the new item into the drop down list at the first index in the list (i.e. the top).

Posted in ASP.Net, C#, LINQ, Web Development | Tagged , , , | Comments Off

Create package

How to create a package, with the name PACK1, with one function called F1

CREATE OR REPLACE PACKAGE PACK1 IS
 
	FUNCTION F1 RETURN BOOLEAN;
 
END PACK1;
 
CREATE OR REPLACE PACKAGE BODY PACK1 IS
 
	FUNCTION F1 RETURN BOOLEAN IS
 
	BEGIN
		RETURN TRUE;
	END F1;
 
END PACK1;
Posted in PL/SQL | Tagged , , | Comments Off

Create function

How to create a function, with the name F1, which returns a boolean

CREATE OR REPLACE FUNCTION F1 RETURN BOOLEAN IS
 
BEGIN
	RETURN TRUE;
END F1;
Posted in PL/SQL | Tagged , , | Comments Off

Create procedure

How to create a procedure, with the name P1

CREATE OR REPLACE PROCEDURE P1 AS
  X VARCHAR2(100);
BEGIN
	X := 'AAA';
END P1;
Posted in PL/SQL | Tagged , , | Comments Off

Change column data type

Alter the TELEPHONE datatype from a varchar2 (or anything) to a number.

ALTER TABLE CUSTOMERS MODIFY(TELEPHONE NUMBER);
Posted in SQL | Tagged , , , | Comments Off

Add a column to a table

How to add a column to an existing table.

Adding the column surname, with the type of varchar2 and length of 100, to the table called customers.

ALTER TABLE CUSTOMERS ADD (SURNAME VARCHAR2(100));
Posted in SQL | Tagged , , , | Comments Off

Change column to be not null

Change an existing column to be NOT NULL

ALTER TABLE CUSTOMERS  MODIFY(TELEPHONE  NOT NULL);
Posted in SQL | Comments Off

Drop a column from a table

How to drop a column from an existing table.

Dropping column COL1 from the table called TEST_TABLE.

ALTER TABLE TEST_TABLE DROP COLUMN COL1;
Posted in SQL | Tagged , , , | Comments Off

Flashback

Select from a table, as it stood X minutes ago

/*
--Any DDL on a table will reset the ability to flashback!
--you must have the flashback privilege
example time_units
Day   1
Hour   1/24
Minute   1/1440
Second   1/86400
*/
 
SELECT *
FROM TABLE_NAME
AS OF TIMESTAMP SYSDATE - time_unit;
Posted in SQL | Tagged , , , | Comments Off