Database connection events : OleDbConnection « Database ADO.net « Visual C++ .NET

Home
Visual C++ .NET
1.2D
2.Class
3.Collections
4.Data Type
5.Database ADO.net
6.Delegate
7.Development
8.File Directory
9.Function
10.Generics
11.GUI Form
12.Language Basics
13.Network
14.Reflection
15.Security
16.Statement
17.Structure
18.Thread
19.XML
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Visual C++ .NET » Database ADO.net » OleDbConnection 
Database connection events
 

#include "stdafx.h"

using namespace System;
using namespace System::Data;
using namespace System::Data::OleDb;
using namespace System::Data::SqlClient;

ref struct MyEventHandler
{
    static void StateChange(Object^ sender, StateChangeEventArgs^ e)
    {
        Console::WriteLine(e->CurrentState.ToString());
    }
};

void main()
{
    OleDbConnection^ myOleDbConnection = nullptr;
    SqlConnection^ mySqlConnection = nullptr;
    OleDbConnectionStringBuilder^ connectionBuilder = gcnew OleDbConnectionStringBuilder();
    connectionBuilder->Provider = "Microsoft.Jet.OLEDB.4.0";
    connectionBuilder->DataSource = "music.mdb";
        
    myOleDbConnection = gcnew OleDbConnection(connectionBuilder->ToString());
    myOleDbConnection->Open();
    SqlConnectionStringBuilder^ connectionBuilder2 =gcnew SqlConnectionStringBuilder();
    connectionBuilder2->DataSource = "localhost";
    connectionBuilder2->InitialCatalog = "ultramax";
    connectionBuilder2->UserID = "sa";
    connectionBuilder2->Password = "";
        
    mySqlConnection = gcnew SqlConnection(connectionBuilder2->ToString());
    mySqlConnection->StateChange += gcnew StateChangeEventHandler(MyEventHandler::StateChange);
        
    mySqlConnection->Open();
        
    Console::WriteLine("Database: {0}", mySqlConnection->Database);
    Console::WriteLine("DataSource: {0}", mySqlConnection->DataSource);
    Console::WriteLine("ServerVersion: {0}",mySqlConnection->ServerVersion);
    Console::WriteLine("Workstation ID: {0}",mySqlConnection->WorkstationId);
    myOleDbConnection->Close();
    mySqlConnection->Close();


   
  
Related examples in the same category
1.Database Events
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.