Tehrik-e-Insaaf

Earn 600$ by Clicking on each Ad

GoWellUp.com

Thursday, November 6, 2008

Oracle Spatial Queries



Table Creation in Oracle Spatial (DDL Command)

CREATE TABLE mylake ( feature_id NUMBER PRIMARY KEY, name VARCHAR2(32),
shape MDSYS.SDO_GEOMETRY);


Insert (DML Command) in Oracle Spatial

INSERT INTO mylake VALUES( 10, -- feature_id 'Lake Calhoun', -- name MDSYS.SDO_GEOMETRY(2003,NULL,NULL,MDSYS.SDO_ELEM_INFO_ARRAY(1,1003,1, 19,2003,1),MDSYS.SDO_ORDINATE_ARRAY(0,0, 10,0, 10,10, 0,10, 0,0, 4,4, 6,4, 6,6, 4,6, 4,4)
));


Querying

SELECT name boat_nameFROM mylake tWHERE feature_id = 12AND SDO_FILTER(t.shape, mdsys.sdo_geometry(2003,NULL,NULL, mdsys.sdo_elem_info_array(1,1003,1), mdsys.sdo_ordinate_array(2,2, 5,2, 5,5, 2,5, 2,2)),
'querytype=WINDOW') = 'TRUE';


This query selects all boats that have geometry with an indexed grid square within the polygon defined. This doesn't necessarily mean the returned boats are within the rectangle or if they are just touching the defined rectangle. To obtain an exact query, a second function called SDO_RELATE must be executed. SDO_RELATE looks at two geometries and determines if they interact in a specified way. It is important to note that SDO_RELATE only works on two-dimensional data. It is defined below.

SDO_RELATE(geometry1 MDSYS.SDO_GEOMETRY, geometry2 MDSYS.SDO_GEOMETRY, params VARCHAR2)

SDO_RELATE arguments are the same as those for SDO_FILTER with the exception of the last argument. The params argument has a masktype value in addition to the querytype value. The masktype value can take the values listed below.

  • DISJOINT — the boundaries and interiors do not intersect
  • TOUCH — the boundaries intersect but the interiors do not intersect
  • OVERLAPBDYDISJOINT — the interior of one object intersects the boundary and interior of the other object, but the two boundaries do not intersect. This relationship occurs, for example, when a line originates outside a polygon and ends inside that polygon.
  • OVERLAPBDYINTERSECT — the boundaries and interiors of the two objects intersect
  • EQUAL — the two objects have the same boundary and interior
  • CONTAINS — the interior and boundary of one object is completely contained in the interior of the other object
  • COVERS — the interior of one object is completely contained in the interior of the other object and their boundaries intersect
  • INSIDE — the opposite of CONTAINS. A INSIDE B implies B CONTAINS A.
  • COVEREDBY — the opposite of COVERS. A COVEREDBY B implies B COVERS A.
  • ON — the interior and boundary of one object is on the boundary of the other object (and the second object covers the first object). This relationship occurs, for example, when a line is on the boundary of a polygon.
  • ANYINTERACT — the objects are non-disjoint.
To select all boats that are inside a defined rectangle the following query would work:

SELECT name boat_nameFROM mylake tWHERE feature_id = 12AND SDO_FILTER(t.shape, mdsys.sdo_geometry(2003,NULL,NULL, mdsys.sdo_elem_info_array(1,1003,1), mdsys.sdo_ordinate_array(2,2, 5,2, 5,5, 2,5, 2,2)), 'querytype=WINDOW') = 'TRUE'AND SDO_RELATE(t.shape, mdsys.sdo_geometry(2003,NULL,NULL, mdsys.sdo_elem_info_array(1,1003,1), mdsys.sdo_ordinate_array(2,2, 5,2, 5,5, 2,5, 2,2)), 'masktype=INSIDE querytype=WINDOW') = 'TRUE'

It is also possible to combine masktypes to select sites that are inside or touching the defined polygon with the query below.

SELECT feature_id idFROM mylake tWHERE feature_id = 12AND SDO_FILTER(t.shape, mdsys.sdo_geometry(2003,NULL,NULL, mdsys.sdo_elem_info_array(1,1003,1), mdsys.sdo_ordinate_array(2,2, 5,2, 5,5, 2,5, 2,2)), 'querytype=WINDOW') = 'TRUE'AND SDO_RELATE(t.shape, mdsys.sdo_geometry(2003,NULL,NULL, mdsys.sdo_elem_info_array(1,1003,1), mdsys.sdo_ordinate_array(2,2, 5,2, 5,5, 2,5, 2,2)), 'masktype=INSIDE+TOUCH querytype=WINDOW') = 'TRUE'

Wednesday, October 22, 2008

How to change the default form in windows application in c#.net

Go to Program.cs of your application and replace the form name with your form name in Application.Run

Example

Application.Run(new MainForm());

How to fill the datagrid with the data from database using datasets

1. Make connection String and selection statement
SqlConnection conn = new SqlConnection(@"Data Source=192.125.5.1;Initial Catalog=Test;User ID=sa;Password=sa;");
string getCommand = @"select * from dbo.compDetails";

2. Declare the object of command & give the respective parameters
//give selection statement
SqlCommand cmd = new SqlCommand(getCommand);
//give the command type
cmd.CommandType = CommandType.Text;
//give connection object
cmd.Connection = conn;

3. Declare the object of SqlDataAdpater & give command object
SqlDataAdapter da = new SqlDataAdapter(cmd);

4. Declare the object of dataset as container of data
DataSet ds = new DataSet();

5. Open the connection
conn.Open();

6. Fill the object of data Adapter with dataset object
da.Fill(ds, "dbo.complaints");

7. Provide the dataset object as a source to dataGrid
this.dataGrid1.DataSource = ds.Tables[0];

8. Close the connection
conn.Close();


Example:

public void getData()
{
SqlConnection conn = new SqlConnection(@"Data Source=192.125.5.1;Initial Catalog=Test;User ID=lrmis;Password=lrmis;");
string getCommand = @"select * from dbo.compDetails";
SqlCommand cmd = new SqlCommand(getCommand);
cmd.CommandType = CommandType.Text;
cmd.Connection = conn;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
conn.Open();
da.Fill(ds, "dbo.complaints");
this.dataGrid1.DataSource = ds.Tables[0];
conn.Close();
}

How to Insert Data in Database in c#

1. First of all make connection string
string connString="Data Source=databasename;Initial Catalog=Test;User ID=sa;Password=sa;"
SqlConnection conn = new SqlConnection(connString);

2. Open the connection
conn.Open();

3. Write the insert command
string insertCommand= @"insert into dbo.compDetails(OwnerId, compName, compAddress, compPhone) values('" + compId + "','" + this.txtCompaName.Text + "','" + this.txtCompAddress.Text + "','" + this.txtCompPhone.Text + "')";

SqlCommand cmdInsert = new SqlCommand(insertCommand, conn);

4. Execute the command
cmdInsert.ExecuteScalar();

5. Close the connection
conn.Close();


Example:

public void setData()
{

string connString="Data Source=databasename;Initial Catalog=Test;User ID=sa;Password=sa;"
SqlConnection conn = new SqlConnection(connString);
conn.Open();
Guid compId = Guid.NewGuid();
string insertCommand= @"insert into dbo.compDetails(OwnerId, compName, compAddress, compPhone) values('" + compId + "','" + this.txtCompaName.Text + "','" + this.txtCompAddress.Text + "','" + this.txtCompPhone.Text + "')";
SqlCommand cmdInsert = new SqlCommand(insertCommand, conn);
cmdInsert.ExecuteScalar();
conn.Close();

}

Monday, September 29, 2008

.Net Remoting

While Web services are arguably the best way for clients outside of your organization to access components, what about components within your organization? Many companies are building Web services and using them internally. There is nothing wrong with this approach, but it doesn't provide the best performance. If components are created in .NET and the client applications are .NET, you can place components on shared servers and access them via remoting.
Remoting is the .NET technology that replaces DCOM allowing you to communicate between a client application and components in a binary format. As a result, remotable components are faster than Web services. However, creating remotable components is more difficult because you must add additional code to your components. This code isn't much more complicated than its Web service counterpart, but you cannot directly instantiate a remote component. Instead, you must create a host application that instantiates the component and listens for requests. The good news is that this host can be a Windows service, a Windows application, a console application, or anything that can run and hold the object open.
Not only do you have to create a host application, you must also make several decisions about the remotable object, such as which channel to use. .NET supports both HTTP and TCP channels. The HTTP channel actually uses the SOAP protocol to transport messages to and from remotable objects; this means all messages are serialized to XML. The TCP channel uses a binary stream to transport the messages.
.NET is architected in such a way that remotable components can change channels without being recompiled. You can place the channel information in a configuration file and change from TCP to HTTP or vice versa without recompiling the application. Similarly, you can change a configuration file for the client to match the channel that the host is using.

Wednesday, September 24, 2008

Pakistan Ranks 62nd in Global IT Competitiveness Index

Pakistan ranks 62nd in the world in the 2008 Information Technology (IT) industry competitiveness index, falling two place; from its 2007 ranking of 60 in the index. In comparison, most neighbouring South Asian countries were ranked more favourably; for example India ranked 48th, Sri Lanka ranked 54th and Bangladesh ranked 60th.These are among the findings of a new study issued by the Economist intelligence Unit and sponsored by the Business Software Alliance (BSA). The study, now in its second year, assesses and compares the IT industry environments of 66 countries to determine the extent to which they enable IT sector competitiveness.Although the top 20 economies remain the same from one year ago, nine countries moved up and 11 went down in the rankings. Three countries in the top five are, new: Taiwan, Sweden and, Denmark. The top five countries in Asia-pacific Region are Taiwan, Australia, South Korea, Singapore and Japan.-PR

Tuesday, September 23, 2008

Introducing Cache Dependencies:
As time passes, the data source may change in response to other actions. However, if your code uses caching, you may remain unaware of the changes and continue using out-of-date information from the cache. To help mitigate this problem, ASP.NET supports cache dependencies. Cache dependencies allow you to make a cached item dependent on another resource so that when that resource changes the cached item is removed automatically. ASP.NET includes three types of dependencies:
  • Dependencies on other cache items.
  • Dependencies on files or folders.
  • Dependencies on a database query.
Cache Notifications in SQL Server 2000:
Before you can use SQL Server cache invalidation, you need to enable notifications for the database. This task is performed with the aspnet_regsql.exe command-line utility, which is located in the c:\[WinDir]\Microsoft.NET\Framework\[Version] directory. To enable notifications, you need to use the -ed command-line switch. You also need to identify the server (use -E for a trusted connection and -S to choose a server other than the current computer) and the database (use -d). Here's an example that enables notifications for the Northwind database on the current server:
aspnet_regsql -ed -E -d
NorthwindAfter executing this command, a new table named SqlCacheTablesForChangeNotification is added to the database Northwind. The SqlCacheTablesForChangeNotification table has three columns: tableName, notificationCreated, and changeId. This table is used to track changes. Essentially, when a change takes place, a record is written into this table. The SQL Server polling queries this table. Also a set of stored procedures is added to the database.
How Notificaions Works:
The AspNet_SqlCacheTablesForChangeNotification contains a single record for every table you're monitoring. When you make a change in the table (such as inserting ,deleting or updating a record), the changeId column is incremented by 1 -see AspNet_SqlCacheUpdateChangeIdStoredProcedure procedure-. ASP.NET queries this table repeatedly and keeps track of the most recent changeId values for every table. When this value changes in a subsequent read, ASP.NET knows that the table has changed.
In this scenario, Any change to the table is deemed to invalidate any query for that table. In other words, if you use this query:
SELECT * FROM Products WHERE CategoryID=1

The caching still works in the same way. That means if any product record is touched, even if the product resides in another category (and therefore isn't one of the cached records), the notification is still sent and the cached item is considered invalid. Also keep in mind it doesn't make sense to cache tables that change frequently.

Enable ASP.Net Polling:
To enable ASP.NET polling , you need to use the element in the web.config file. Set the enabled attribute to true to turn it on, and set the pollTime attribute to the number of milliseconds between each poll. (The higher the poll time, the longer the potential delay before a change is detected.) You also need to supply the connection string information.

Creating the Cache Dependency:
Now that we've seen how to set up a database to support SQL Server notifications, the only remaining detail is the code, which is quite straightforward. We can use our cache dependency with programmatic data caching, a data source control, and output caching.
For programmatic data caching, we need to create a new SqlCacheDependency and supply that to the Cache.Insert() method. In the SqlCacheDependency constructor, you supply two strings. The first is the name of the database you defined in the element in the section of the web.config file e.g: Northwind. The second is the name of the linked table e.g: Products.Example:private static void CacheProductsList(List products){
SqlCacheDependency sqlDependency = new SqlCacheDependency("Northwind", "Products");HttpContext.Current.Cache.Insert("ProductsList", products, sqlDependency, DateTime.Now.AddDays(1), Cache.NoSlidingExpiration);
}
private static List GetCachedProductList(){
return HttpContext.Current.Cache["ProductsList"] as List;
}
NWProductItem is business class, and here we are trying to cache a list of NWProductItem instead of DataSet or DataTable.The following method is used by an ObjectDataSource Control to retrieve List of Products
public static List GetProductsList(int catId, string sortBy){
//Try to Get Products List from the CacheList products = GetCachedProductList();if (products == null){
//Products List not in the cache, so we need to query the Database by using a Data LayerNWProductsDB db = new NWProductsDB(_connectionString);DbDataReader reader = null;products = new List(80);
if (catId > 0){
//Return Product List from the Data Layerreader = db.GetProductsList(catId);
}else{
//Return Product List from the Data Layerreader = db.GetProductsList();
}//Create List of Products -List if NWProductItem-products = BuildProductsList(reader);reader.Close();//Add entry to products list in the CacheCacheProductsList(products);
}products.Sort(new NWProductItemComparer(sortBy));if (sortBy.Contains("DESC")) products.Reverse();return products;
}
To perform the same trick with output caching, you simply need to set the SqlDependency property with the database dependency name and the table name, separated by a colon: <%@ OutputCache Duration="600" SqlDependency="Northwind:Products" VaryByParam="none" %>

<%@ OutputCache Duration="600" SqlDependency="Northwind:Products" VaryByParam="none" %>The same technique works with the SqlDataSource and ObjectDataSource controls:

Monday, September 22, 2008

ASP.NET Impersonation

Another important security feature is the ability to control the identity under which code is executed. Impersonation is when ASP.NET executes code in the context of an authenticated and authorized client. By default, ASP.NET does not use impersonation and instead executes all code using the same user account as the ASP.NET process, which is typically the ASPNET account.
This is contrary to the default behavior of ASP, which uses impersonation by default. In Internet Information Services (IIS) 6, the default identity is the NetworkService account.

Note Impersonation can significantly affect performance and scaling. It is generally more expensive to impersonate a client on a call than to make the call directly.

Using impersonation, ASP.NET applications can optionally execute the processing thread using the identity of the client on whose behalf they are operating. You usually use impersonation for resource access control. Delegation is a more powerful form of impersonation and makes it possible for the server process to access remote resources while acting as the client.
If you enable impersonation, ASP.NET can either impersonate the authenticated identity received from IIS or one specified in the application's Web.config file. You have the following three options when configuring impersonation:
  • Impersonation is disabled. This is the default setting. For backward compatibility with ASP, you must enable impersonation and change the ASP.NET process identity to use the Local System account. In this instance, the ASP.NET thread runs using the process token of the application worker process regardless of which combination of IIS and ASP.NET authentication is used. By default, the process identity of the application worker process is the ASPNET account.

  • Impersonation enabled. In this instance, ASP.NET impersonates the token passed to it by IIS, which is either an authenticated user or the anonymous Internet user account (IUSR_machinename).

  • Impersonation enabled for a specific identity. In this instance, ASP.NET impersonates the token generated using an identity specified in the Web.config file. userName="domain\user"
    password="password" />

If the application resides on a UNC share, ASP.NET always impersonates the IIS UNC token to access that share unless a configured account is used. If you provide an explicitly configured account, ASP.NET uses that account in preference to the IIS UNC token.
You should exercise care when using impersonation because it makes it possible for an application to potentially process code using permissions not anticipated by the application designer. For example, if your application impersonates an authenticated intranet user, that application possesses administrative privileges when impersonating a user with those privileges. Likewise, if the impersonated user possesses more restrictive permissions than anticipated, the user may not be able to use the application.

Delegates in C#.Net

A delegate is a type-safe object that can point to another method (or possibly multiple methods) in the application, which can be invoked at later time.

A delegate type maintains three important pices of information :
1. The name of the method on which it make calls.
2. Any argument (if any) of this method.
3. The return value (if any) of this method.


when you want to create a delegate in C# you make use of delegate keyword.The name of your delegate can be whatever you desire. However, you must define the delegate to match the signature of the method it will point to. fo example the following delegate can point to any method taking two integers and returning an integer.public delegate int DelegateName(int x, int y);A Delegate Usage Example
namespace MyFirstDelegate
{
//This delegate can point to any method,
//taking two integers and returning an
//integer.
public delegate int MyDelegate(int x, int y);
//This class contains methods that MyDelegate will point to.
public class MyClass
{
public static int Add(int x, int y)
{
return x + y;
}
public static int Multiply(int x, int y)
{
return x * y;
}
}
class Program
{
static void Main(string[] args)
{
//Create an Instance of MyDelegate
//that points to MyClass.Add().
MyDelegate del1 = new MyDelegate(MyClass.Add);
//Invoke Add() method using the delegate.
int addResult = del1(5, 5);
Console.WriteLine("5 + 5 = {0}\n", addResult);
//Create an Instance of MyDelegate
//that points to MyClass.Multiply().
MyDelegate del2 = new MyDelegate(MyClass.Multiply);
//Invoke Multiply() method using the delegate.
int multiplyResult = del2(5, 5);
Console.WriteLine("5 X 5 = {0}", multiplyResult);
Console.ReadLine();
}
}}