// BeginVersionCpp.cpp
// compile with: /EHsc
#import "msado15.dll" no_namespace rename("EOF", "EndOfFile")
#include <ole2.h>
#include <stdio.h>
#include <conio.h>
// Function declarations
inline void TESTHR(HRESULT x) { if FAILED(x) _com_issue_error(x); };
void VersionX();
void PrintProviderError(_ConnectionPtr pConnection);
void PrintComError(_com_error &e);
int main() {
    if (FAILED(::CoInitialize(NULL)))
        return -1;
    VersionX();
    ::CoUninitialize();
}
void VersionX() {
    HRESULT hr = S_OK;
   _bstr_t strCnn("Provider='sqloledb'; Data Source='My_Data_Source'; Initial Catalog='pubs'; Integrated Security='SSPI';");
    // Define ADO object pointers.  Initialize pointers on define.
    // These are in the ADODB::  namespace.
    _ConnectionPtr pConnection = NULL;
    try {
        // Open connection.
        TESTHR(pConnection.CreateInstance(__uuidof(Connection)));
        pConnection->Open (strCnn, "", "", adConnectUnspecified);
        printf("ADO Version   : %s\n\n",(LPCSTR) pConnection->Version);
        printf("DBMS Name   : %s\n\n",(LPCSTR) (_bstr_t)
            pConnection->Properties->GetItem("DBMS Name")->Value);
        printf("DBMS Version   : %s\n\n",(LPCSTR) (_bstr_t)
            pConnection->Properties->GetItem("DBMS Version")->Value);
        printf("OLE DB Version   : %s\n\n",(LPCSTR) (_bstr_t)
            pConnection->Properties->GetItem("OLE DB Version")->Value);
        printf("Provider Name   : %s\n\n",(LPCSTR) (_bstr_t)
            pConnection->Properties->GetItem("Provider Name")->Value);
        printf("Provider Version   : %s\n\n",(LPCSTR) (_bstr_t)
            pConnection->Properties->GetItem("Provider Version")->Value);
        printf("Driver Name   : %s\n\n",(LPCSTR) (_bstr_t)
            pConnection->Properties->GetItem("Driver Name")->Value);
        printf("Driver Version   : %s\n\n",(LPCSTR) (_bstr_t)
            pConnection->Properties->GetItem("Driver Version")->Value);
        printf("Driver ODBC Version   : %s\n\n",(LPCSTR) (_bstr_t)
            pConnection->Properties->GetItem("Driver ODBC Version")->Value);
    }
    catch (_com_error &e) {
        // Notify the user of errors if any.
        PrintProviderError(pConnection);
        PrintComError(e);
    }
    if (pConnection)
        if (pConnection->State == adStateOpen)
            pConnection->Close();
}
void PrintProviderError(_ConnectionPtr pConnection) {
    // Print Provider Errors from Connection object.
    // pErr is a record object in the Connection's Error collection.
    ErrorPtr pErr = NULL;
    if ( (pConnection->Errors->Count) > 0) {
        long nCount = pConnection->Errors->Count;
        // Collection ranges from 0 to nCount -1.
        for ( long i = 0 ; i < nCount ; i++) {
            pErr = pConnection->Errors->GetItem(i);
            printf("Error number: %x\t%s\n", pErr->Number, (LPCSTR) pErr->Description);
        }
    }
}
void PrintComError(_com_error &e) {
   _bstr_t bstrSource(e.Source());
   _bstr_t bstrDescription(e.Description());
    // Print Com errors.
   printf("Error\n");
   printf("\tCode = %08lx\n", e.Error());
   printf("\tCode meaning = %s\n", e.ErrorMessage());
   printf("\tSource = %s\n", (LPCSTR) bstrSource);
   printf("\tDescription = %s\n", (LPCSTR) bstrDescription);
}
9 Comments
  • cheap flights to vegas
    says:

    Hi there! This article couldn’t be written any better!
    Going through this article reminds me of my previous
    roommate! He constantly kept preaching about this. I will send this
    post to him. Pretty sure he will have a very good read. I appreciate
    you for sharing!

  • Florentino Zeno
    says:

    I simply want to mention I am just new to blogging and site-building and certainly liked you’re blog. Very likely I’m want to bookmark your website . You really have superb writings. Thanks a lot for sharing with us your blog.

  • cbd oil that works 2020
    says:

    Do you mind if I quote a couple of your posts as long as I
    provide credit and sources back to your site? My blog is in the exact same niche as yours and my users
    would genuinely benefit from a lot of the information you present
    here. Please let me know if this ok with you. Thank you!

  • cbd oil that works 2020
    says:

    Can I just say what a comfort to discover somebody who truly knows what they’re talking about over
    the internet. You definitely understand how to bring an issue to light and make it important.
    A lot more people should look at this and understand this side of the story.
    It’s surprising you are not more popular given that you surely have
    the gift.

  • http://tinyurl.com
    says:

    Hey I know this is off topic but I was wondering if
    you knew of any widgets I could add to my blog that automatically tweet my newest twitter updates.
    I’ve been looking for a plug-in like this for quite some time
    and was hoping maybe you would have some experience with something like
    this. Please let me know if you run into anything.

    I truly enjoy reading your blog and I look forward to your new updates.

댓글 남기기