// *************************************************************************** // Copyright (C) 1991-2002 SQLDev.Net // // $BeginHeader$ // // @file@: Connect.cpp // @author@: Gert E.R. Drapers (GertD@SQLDev.Net) // @description@: Example SQL-DMO Connecting // @remarks@: // @created@: 2002-12-30 // @lastsaved@: 2002-12-30 // // update history: // @version@ @initials@ @updatedate@ @release@ @description@ // 00000 GED 2002-12-30 v1.0.0.0 created // // @EndHeader@ // *************************************************************************** #define STRICT // strict type checking #define WIN32_LEAN_AND_MEAN // do not include the world #define INC_OLE2 // include OLE/COM files #include #include #include #include #import "C:\Program Files\Microsoft SQL Server\80\Tools\Binn\sqldmo.dll" no_namespace INT _tmain(INT argc, TCHAR* argv[], TCHAR* envp[]) { HRESULT hr; if SUCCEEDED(hr = CoInitialize(NULL)) { try { _SQLServer2Ptr spSQLServer; if (SUCCEEDED(spSQLServer.CreateInstance(__uuidof(SQLServer2)))) { try { spSQLServer->LoginSecure = TRUE; spSQLServer->Connect(_T("(local)\\dev")); _tprintf(_T("Connected to %s"), (LPTSTR) spSQLServer->Name); spSQLServer->DisConnect(); } catch(_com_error pCE) { _tprintf(_T("\n%s Error: %ld\r\n%s\r\n%s\r\n"), (TCHAR*)pCE.Source(), pCE.Error(), (TCHAR*)pCE.Description(), (TCHAR*)pCE.ErrorMessage()); } } else { _tprintf(_T("Unable to create the SQL Server object.\n")); } } catch(_com_error pCE) { _tprintf(_T("\n%s Error: %ld\r\n%s\r\n%s\r\n"), (TCHAR*)pCE.Source(), pCE.Error(), (TCHAR*)pCE.Description(), (TCHAR*)pCE.ErrorMessage()); } CoUninitialize(); } else { _tprintf(_T("Call to CoInitialize failed.\n")); } return(0); }