Docstoc

Sample Access Database .Mdb

Document Sample
Sample Access Database .Mdb Powered By Docstoc
					A Walkthrough .NET
                 ADO.NET

• Microsoft ActiveX Data Objects

• One of the ways that .NET provides to access Database
  servers

• You can also use Entity SQL language or LINQ provided
  by Microsoft to query entities from databases
             ADO.NET contd…
Database providers that can be used with ADO.NET
–   Data Provider for SQL Server (System.Data.SqlClient)
–   Data Provider for OLEDB (System.Data.OleDb).
–   Data Provider for ODBC (System.Data.Odbc).
–   Data Provider for Oracle (System.Data.OracleClient)

Key features to remember
Important Objects: DataSet: Container to Store the result set
Connection: Standard connection string to create a connection commands-
  to be executed remotely on database
Data Reader: Reads stored Data Set
    ADO.NET data provider objects

•   the Connection object (SqlConnection, OleDbConnection,
    OdbcConnection, OracleConnection)
•   the Command object (SqlCommand, OleDbCommand, OdbcCommand,
    OracleCommand)
•   the DataReader object (SqlDataReader, OleDbDataReader,
    OdbcDataReader, OracleDataReader)
•   and the DataAdapter object (SqlDataAdapter, OleDbDataAdapter,
    OdbcDataAdapter, OracleDataAdapter)
Connection Strings( MS Access example)

Open connection to Access database:
"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\App1\Your_Database_Name.mdb; User
Id=admin; Password="
Open connection to Access database using Workgroup (System database):
"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\App1\Your_Database_Name.mdb; Jet
OLEDB:System Database=c:\App1\Your_System_Database_Name.mdw"
Open connection to password protected Access database:
"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\App1\Your_Database_Name.mdb; Jet
OLEDB:Database Password=Your_Password"
Open connection to Access database located on a network share:
"Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=\\Server_Name\Share_Name\Share_Path\Your_Database_Name.mdb"
Open connection to Access database located on a remote server:
"Provider=MS Remote; Remote Server=http://Your-Remote-Server-IP; Remote
Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\App1\Your_Database_Name.mdb"
                 Data Adapter

The DataAdapter includes three main methods:
   – Fill (populates a DataSet with data).
   – FillSchema (queries the database for schema information that is
     necessary to update).
   – Update (to change the database, DataAdapter calls the
     DeleteCommand, the InsertCommand and the UpdateCommand
     properties).
                        Entity Schema XML
•   <EntityType Name="Employee" Key="EmployeeID">
•
•     <Property Name="EmployeeID" Type="Int32" Nullable="false" />
•     <Property Name="LoginID" Type="String" Nullable="false"
•        MaxLength="256" />
•     <Property Name="Title" Type="String" Nullable="false"
•        MaxLength="50" />
•     <Property Name="BirthDate" Type="DateTime" Nullable="false" />
•     <Property Name="HireDate" Type="DateTime"
•        Nullable="false"/>
•     <Property Name="SalariedFlag" Type="Boolean"
•        Nullable="false" />
•     <Property Name="VacationHours" Type="Int16"
•        Nullable="false" />
•     <Property Name="SickLeaveHours" Type="Int16"
•        Nullable="false" />
•     <Property Name="CurrentFlag" Type="Boolean"
•        Nullable="false" />
•    <!--Other properties-->
•
•     <NavigationProperty Name="Contact"
•       Relationship="AdventureWorksModel.FK_Employee_Contact_ContactID"
•       FromRole="Employee" ToRole="Contact" />
•
•     <NavigationProperty Name="Managed_Employees"
•       Relationship="AdventureWorksModel.FK_Employee_Employee_ManagerID"
•       FromRole="Employee" ToRole="ManagedEmployee" />
•
•      </EntityType>
                             .NET Remoting
• The latest replacement for .NET remoting in the new framework is
  Windows Communication Foundation

•   Channels are objects that transport messages between applications across remoting boundaries, whether
    between application domains, processes, or computers. A channel can listen on an endpoint for inbound
    messages, send outbound messages to another endpoint, or both. This enables you to plug in a wide range of
    protocols, even if the common language runtime is not at the other end of the channel.


• Channels available are Tcp and Http Channel Objects

• Remotable Type Objects: Create a Remotable type which is derived
  from MarshalByRefObject
          .NET Remoting (Client)
• Host Tasks
   – Design the service
        • Build a hosting application
        • Activate Remote objects via server or client
        • Choose a channel of communication
   – Remoting hosts can be windows applications, console applications, windows
     form applications, and Internet Information Services or ASP.NET
   – Register the channel in the host/ or If you use configuration file, you must load
     the file into the system by calling RemotingConfiguration.Configure



• Client Tasks
   – Either programatically configure or use a configure file similar to Host
   – Configure the channel
   – Design the service
               Sample Schema files for
               Host/Client Applications
<configuration>
    <system.runtime.remoting>
            <application>
                        <service>
                        <wellknown mode="Singleton" type="RemotableType, RemotableType"
    objectUri="RemotableType.rem" />
                        </service>
                        <channels>
                         <channel ref="http" port="8989"/>
                         </channels>
            </application>
    </system.runtime.remoting>
</configuration>



Configure using:   RemotingConfiguration.Configure("Listener.exe.config", false);
                  Activation of an obj
•   In a remoting application it is important to know when and how a remote
    object is created and initialized and how it is activated.

•   Server activation:
     – Server activated objects are created by the server only when needed.
     – Singleton objects are objects that will have only one instance and a default
       lifetime.
     – Single call are given memory at each client method invocation call, hence no
       lifetime lease.

     – For server side activation use: Activator.GetObject
•   Client activation
     – Similar to local objects, lifetimes controlled by calling application domain
     – The server instantiates a remote obj and returns a reference back to the client.
       The client uses that objRef to create proxy to the remote Obj

     – For client side activation: Activator.CreateInstance
                          Lifetime Leases
•   PropertyDescriptionInitialLeaseTimeSpecifies the initial span of time that an object remains in
    memory before the lease manager begins the process of deleting the object. In the configuration
    file, this is the leaseTime attribute of the <lifetime> Element configuration element. The default is
    5 minutes. A lease time of 0 sets the lease to an infinite lifetime.

•   CurrentLeaseTimeSpecifies the span of time left before the lease expires. When a lease is
    renewed, its CurrentLeaseTime is set to the maximum of theCurrentLeaseTime or the

•   RenewOnCallTime.RenewOnCallTimeSpecifies the maximum time span that
    the CurrentLeaseTime is set to after each remote call to the object. The default is 2 minutes.

•   SponsorshipTimeoutSpecifies the time that the lease manager waits for the sponsor to respond
    when notified that a lease has expired. If the sponsor does not respond in the specified time, the
    sponsor is removed and another sponsor is called. If there are no more sponsors, the lease
    expires and the remote object is marked for garbage collection. If the value is 0 (TimeSpan.Zero),
    the lease does not register sponsors. The default is 2 minutes.

•   LeaseManagerPollTimeSpecifies the amount of time that the lease manager sleeps after
    checking for expired leases. The default is 10 seconds.

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:264
posted:7/28/2011
language:English
pages:12
Description: Sample Access Database .Mdb document sample