News

Tuesday, July 3, 2007

How To Access an Oracle Database by Using the OLE DB .NET Data Provider and Visual C# .NET

SUMMARY

This article demonstrates how to use the ADO.NET OLE DB managed provider to access an Oracle database.
 

Requirements

The following list outlines the recommended hardware, software, network infrastructure, and service packs that you need:
Microsoft Windows 2000 Professional, Windows 2000 Server, Windows 2000 Advanced Server, or Windows NT 4.0 Server
Oracle Client tools (installed on the computer)
Microsoft Visual Studio .NET
This article assumes that you are familiar with the following topics:
Visual Studio .NET
ADO.NET fundamentals and syntax
Oracle connectivity
 

Steps to Access an Oracle Database

1. In Oracle, create a table named TestTable as follows:
Create Table TestTable (c1 char(5)); 					
2. Insert data into TestTable as follows:
Insert into TestTable c1 values('Test1'); Insert into TestTable c1 values('Test2'); Insert into TestTable c1 values('Test3'); 					
3. Start Visual Studio .NET.
4. Create a new Windows Application project in Visual C# .NET.
5. Make sure that your project contains a reference to the System.Data namespace, and add a reference to this namespace if it does not.
6. Drag a Button control to Form1, and change its Name property to btnTest.
7. Use the using statement on the System, System.Data, and System.Data.OleDb namespaces so that you are not required to qualify declarations in those namespaces later in your code.
using System; using System.Data; using System.Data.OleDb; 					
8. Switch to Form view, and double-click btnTest to add the click event handler. Add the following code to the handler:
String sConnectionString =     "Provider=MSDAORA.1;User ID=myUID;password=myPWD;      Data Source=myOracleServer;Persist Security Info=False"; String mySelectQuery =     "SELECT * FROM TestTable where c1 LIKE ?";  OleDbConnection myConnection = new OleDbConnection(sConnectionString); OleDbCommand myCommand = new OleDbCommand(mySelectQuery, myConnection);  myCommand.Parameters.Add("@p1", OleDbType.Char, 5).Value = "Test%"; myConnection.Open(); OleDbDataReader myReader = myCommand.ExecuteReader(); int RecordCount=0; try {     while (myReader.Read())     {         RecordCount = RecordCount + 1; 	MessageBox.Show(myReader.GetString(0).ToString());     }     if (RecordCount == 0)     { 	MessageBox.Show("No data returned");     }     else     { 	MessageBox.Show("Number of records returned: " + RecordCount);     } } catch (Exception ex) {     MessageBox.Show(ex.ToString()); } finally {     myReader.Close();     myConnection.Close(); } 					
9. Save your project.
10. On the Debug menu, click Start to run your project.
11. Click the button to display the data.

Tuesday, June 26, 2007

HOW TO Create a Local Web Server ASP.NET Application

Create a Local Web Server ASP.NET Application

1. Start Microsoft Visual Studio .NET.
2. On the File menu, point to New, and then click Project.
3. In the New Project dialog box, click Visual Basic Projects under Project Types, and then click ASP.NET Web Application under Templates to create the project in Visual Basic.

NOTE: Alternatively, you can click Visual C# Project under Project Types, and then click ASP.NET Web Application under Templates to create the project in Visual C#.
4. In the IIS Web folder (which is typically /wwwroot), create the essential project references and files to use as a starting point for your application:
AssemblyInfo (.vb file for Visual Basic or .cs file for Visual C#): Use this file to describe the assembly and to specify version information.
using System.Reflection; using System.Runtime.CompilerServices; [assembly: AssemblyTitle("")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("")] [assembly: AssemblyCopyright("")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")]		 [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyDelaySign(false)] [assembly: AssemblyKeyFile("")] [assembly: AssemblyKeyName("")] 						
Global.asax: The basic file Global.asax.cs that contains code for responding to application-level events that ASP.NET raises.
<%@ Application Codebehind="Global.asax.cs" Inherits="WebApplication2.Global" %> 							
NOTE: The source of Global.asax.cs is not included in this document.
Styles.css: This file contains the default HTML style settings.
Web.config: This is an application configuration file that contains settings that are specific to an application. This file contains configuration settings that the common language runtime reads (such as assembly binding policy, remoting objects, and so on), and settings that the application can read.
Projectname.vsdisco: This is an XML-based file that the ASP.NET dynamic XML Web service discovery process uses to identify searchable paths on the Web server.
WebForm1.aspx: This file contains the portion of the default Web Forms page that contains user interface elements (controls), similar to an HTML page.
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs"  AutoEventWireup="false" Inherits="WebApplication2.WebForm1" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >  <html>   <head>     <title>WebForm1</title>     <meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">     <meta name="CODE_LANGUAGE" Content="C#">     <meta name=vs_defaultClientScript content="JavaScript">     <meta name=vs_targetSchema  content="http://schemas.microsoft.com/intellisense/ie5">   </head>   <body MS_POSITIONING="GridLayout">     <form id="Form1" method="post" runat="server">     </form>   </body> </html> 						
Webform1 (.vb file for Visual Basic or .cs file for Visual C#): This file contains a class file for the default Web Forms page that contains the system-generated and user code for the page.
5. After you create the project, you see an empty Web Form with that is named "WebForm1.aspx." This is the workspace of the first page in a project, in which you can place WebForms, HTML forms, Components, Data objects, and Clipboard elements from ToolBox.

Tuesday, June 19, 2007

How To Disable ASP Session State in ASP.NET

SUMMARY

This step-by-step article demonstrates how to disable session state in ASP.NET.

When session state is enabled, ASP.NET creates a session for every user who accesses the application, which is used to identify the user across pages within the application. When session state is disabled, user data is not tracked, and you cannot store information in the Session object or use the Session_OnStart or Session_OnEnd events. By disabling session state, you can increase performance if the application or the page does not require session state to enable it.

In ASP.NET, if you do not use the Session object to store any data or if any of the Session events (Session_OnStart or Session_OnEnd) is handled, session state is disabled. A new Session.SessionID is created every time a single page is refreshed in one browser session.