Database
  Home arrow Database arrow Page 3 - Using ADO with the SQL Native Client
Iron Speed
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Download TestComplete 
Windows Web Hosting
 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
DATABASE

Using ADO with the SQL Native Client
By: Jayaram Krishnaswamy
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 6
    2006-09-25

    Table of Contents:
  • Using ADO with the SQL Native Client
  • Adding Library References and ActiveX Objects
  • Exploring the SQL Native Client
  • Displaying XML data retrieved from SQL 2005

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    Iron Speed
     
    ADVERTISEMENT

    Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!

    Using ADO with the SQL Native Client - Exploring the SQL Native Client
    (Page 3 of 4 )

    The next paragraph shows the code in the command button's click event. Comments are provided on the appropriate parts of the code. It may be interesting to note that once the SQLNCLI provider is used, several of the defaults enter into the connections string. The initial catalog used here is the Northwind database. This is not an example database in the SQL 2005 Server. It was exported to SQL2005 from the SQL 2000 server. For details refer to this link.

    Private Sub Command7_Click()
    'ADODB Stream is declared but not used.
    Dim myStream As New ADODB.Stream
    'declare the ADODB Connection
    Dim myConnection As New ADODB.Connection
    'declare the ADODB Command
    Dim myCommand As New ADODB.Command 'Open the connection using the SQL 
    Native Client
    'Hodentek/Mysorian is the SQL 2005 Server (Mysorian) 'on the machine,
    Hodentek
    myConnection.Open "Provider=SQLNCLI.1;Integrated Security=SSPI;" & _ "Persist Security Info=False; Initial Catalog=Northwind;" & _ "Data Source=Hodentekmysorian" 'use the connection as the Active Connection for the command myCommand.ActiveConnection = myConnection 'explore the various properties for this connection Debug.Print ("Attributes of the Connection: " & myConnection.Attributes) Debug.Print ("Command Time out of the Connection: " &
    myConnection.CommandTimeout) Debug.Print ("Connection string for the Connection: " &
    myConnection.ConnectionString) Debug.Print ("Cursor Location of the connection: " &
    myConnection.CursorLocation) Debug.Print ("The Provider for this Connection: " &
    myConnection.Provider) Debug.Print ("Connection's Default Database: " &
    myConnection.DefaultDatabase) Debug.Print ("Isolation Level for this Connection: " &
    myConnection.IsolationLevel) Debug.Print ("The Mode for this connection: " &
    myConnection.Mode) Debug.Print ("The version used for this connection: " &
    myConnection.Version) Debug.Print ("What is the State of this Connection: " & myConnection.State) 'explore the command created Debug.Print ("Command's Active Connection is: " &
    myCommand.ActiveConnection) Debug.Print ("Command's Timeout is: " & myCommand.CommandTimeout) Debug.Print ("Command's CommandType is: " & myCommand.CommandType) Debug.Print ("Command's Dialect is: " & myCommand.Dialect) Debug.Print ("Command's State is: " & myCommand.State)
    'Elucidating the command's properties further Debug.Print ("Name of Command property 0 is: " &
    myCommand.Properties(0).Name) Debug.Print ("Name of Command property 1 is: " &
    myCommand.Properties(1).Name) Debug.Print ("Name of Command property 2 is: " &
    myCommand.Properties(2).Name) Debug.Print ("Name of Command property 3 is: " &
    myCommand.Properties(3).Name) Debug.Print ("Name of Command property 4 is: " &
    myCommand.Properties(4).Name) Debug.Print ("Name of Command property 5 is: " &
    myCommand.Properties(5).Name) myConnection.Close End Sub

    The properties of the connection and command are printed out to the immediate screen as shown in the next paragraph.

    Attributes of the Connection: 
    0 Command Time out of the Connection: 
    30 Connection string for the Connection: 
    Provider=SQLNCLI.1;Integrated Security=SSPI; Persist Security Info=False;
    Initial Catalog=Northwind; Data Source=Hodentekmysorian;
    Use Procedure for Prepare=1;Auto Translate=True; Packet 
    Size=4096;Workstation ID=HODENTEK; Use Encryption for Data=False; Tag with column collation
    when possible=False; MARS Connection=False; DataTypeCompatibility=0;Trust Server
    Certificate=False Cursor Location of the connection: 2 The Provider for this Connection: SQLNCLI.1 Connection's Default Database: Northwind Isolation Level for this Connection: 4096 The Mode for this connection: 0 The version used for this connection: 2.8 What is the State of this Connection: 1 Command's Active Connection is: Provider=SQLNCLI.1;Integrated
    Security=SSPI; Persist Security Info=False; Initial Catalog=Northwind; Data Source=Hodentekmysorian; Use Procedure for Prepare=1; Auto Translate=True; Packet Size=4096;Workstation ID=HODENTEK; Use Encryption for Data=False; Tag with column collation when
    possible=False; MARS Connection=False; DataTypeCompatibility=0;Trust Server
    Certificate=False Command's Timeout is: 30 Command's CommandType is: 8 Command's Dialect is: {C8B521FB-5CF3-11CE-ADE5-00AA0044773D} Command's State is: 0 '-------------------- Name of Command property 0 is: IAccessor Name of Command property 1 is: IColumnsInfo Name of Command property 2 is: IColumnsRowset Name of Command property 3 is: IConnectionPointContainer Name of Command property 4 is: IConvertType Name of Command property 5 is: IDBAsynchStatus
    These are a few out of 97 properties.
    

    It may be noticed that a shorter connection string was used while opening the connection, but when the connection string was accessed a larger string was returned. These are the defaults.

    Of these properties in the Connection String,  two of them deserve special mention. The DataTypeCompatibility, whose default is 0, refers to the ADO data types. If you want to use the data types that are new in SQL 2005 you should use 80, the other value for this argument. Also you can have the functionality of opening multiple recordsets (resultsets?) only if you set the MARS connection property to True.

    The dialect property which appeared beginning with ADO 2.6 is used mainly in the context of XML streams and refers to the dialect (flavor of syntax) of XML used. The one that is referenced here is the default, a string which is a provider independent Globally Unique Identifier.

    More Database Articles
    More By Jayaram Krishnaswamy


       · If you are looking for data on SQL 2005 Server, this is the fastest. You may also...
     

    DATABASE ARTICLES

    - Database Programming in C# with MySQL : Usin...
    - Formatting Techniques for Data Access from E...
    - Data Access from Excel VBA
    - Generating a Multiple Table Crystal Report u...
    - ADO and the Command Object
    - On Wiring Up an ADO Data Control
    - Reading and Writing to Files on the Intranet
    - Using ADO Record to Create and Navigate Intr...
    - Using Data Access Pages to Access Data on a ...
    - Using ADO with the SQL Native Client
    - ADO`s Stream Object
    - Opening a Record Object Referencing an Open ...
    - Introducing Jasper (SQL Anywhere 10 Beta)
    - Creating a Database Project in VS 2005
    - Manipulating ADO Recordsets




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway