Click here to Skip to main content
15,913,610 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Messge "the device is not ready" occur. Pin
_AnsHUMAN_ 20-Aug-09 21:51
_AnsHUMAN_ 20-Aug-09 21:51 
GeneralRe: Messge "the device is not ready" occur. Pin
Le@rner20-Aug-09 21:57
Le@rner20-Aug-09 21:57 
QuestionConverting CString to int Pin
Le@rner20-Aug-09 18:47
Le@rner20-Aug-09 18:47 
AnswerRe: Converting CString to int Pin
Adam Roderick J20-Aug-09 19:11
Adam Roderick J20-Aug-09 19:11 
GeneralRe: Converting CString to int Pin
Le@rner20-Aug-09 19:37
Le@rner20-Aug-09 19:37 
QuestionRetreive Hard Disk Interface Type Pin
Abinash Mohanty20-Aug-09 18:39
Abinash Mohanty20-Aug-09 18:39 
AnswerRe: Retreive Hard Disk Interface Type Pin
Randor 20-Aug-09 22:32
professional Randor 20-Aug-09 22:32 
QuestionADO Connection String. Pin
forexsurfr20-Aug-09 17:11
forexsurfr20-Aug-09 17:11 
I am currently having problems with my ADO connection string. I have searched all over the internet for a solution to this problem but I have yet to find a solution. Can someone help me with the proper configuration for a SQL OLEDB connection with a windows authentication? Included is my C++ code file. I cannot include my SQL Server signon but can send a printscreen via e-mail attachment.

// ConnectionString.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
// ConnectionStringSampleCpp.cpp
// compile with: /EHsc
//#import "msado15.dll" no_namespace rename("EOF", "EndOfFile")
#import "c:\Program Files\Common Files\System\ADO\msado15.dll" no_namespace rename("EOF", "EOFile")

// Function declarations
inline void TESTHR(HRESULT x) {if FAILED(x) _com_issue_error(x);};
void ConnectionStringX();
_bstr_t GetState(int intState);
void PrintProviderError(_ConnectionPtr pConnection);
void PrintComError(_com_error &e);

int main() {
if (FAILED(::CoInitialize(NULL)))
return 0;

ConnectionStringX();
::CoUninitialize();
}

void ConnectionStringX() {
// Define Connection object pointers. Initialize pointers on define. These are in the ADODB:: namespace
_ConnectionPtr pConnection1 = NULL;
_ConnectionPtr pConnection2 = NULL;
_ConnectionPtr pConnection3 = NULL;
_ConnectionPtr pConnection4 = NULL;

// Define Other Variables
HRESULT hr = S_OK;

try {
// Open a connection using OLE DB syntax.
TESTHR(pConnection1.CreateInstance(__uuidof(Connection)));
//pConnection1->ConnectionString = "Provider='sqloledb';Data Source='(local)';"
// "Initial Catalog='DSNPubs';Integrated Security='SSPI';";
//pConnection1->ConnectionString = "Provider='sqloledb';Server='PCD-LT-MCERTINI\\SQLEXPRESS';"
// "AttachDbFilename='C:\\SQL Server 2000 Sample Databases\\NORTHWND.mdf';Initial Catalog='northwind';Trusted_Connection=Yes;";
pConnection1->ConnectionString = "Provider='SQLOLEDB.1';Persist Security Info='True';User ID='mcertini';Initial Catalog='northwind';Data Source='PCD-LT-MCERTINI\\SQLEXPRESS';";
//pConnection1->ConnectionString = "Provider='SQLNCLI10';Data Source='NORTHWND.mdf';";
pConnection1->ConnectionTimeout = 30;
pConnection1->Open("", "", "",adConnectUnspecified);
printf("cnn1 state: %s\n", (LPCTSTR)GetState(pConnection1->State));

// Open a connection using a DSN and ODBC tags.
// It is assumed that you have create DSN 'DataPubs' with a user name as
// 'MyUserId' and password as 'MyPassword'.
//TESTHR(pConnection2.CreateInstance(__uuidof(Connection)));
//pConnection2->ConnectionString = "DSN=DataPubs;UID=MyUserId;PWD=MyPassword;";
//pConnection2->Open("", "", "", adConnectUnspecified);
//printf("cnn2 state: %s\n", (LPCTSTR)GetState(pConnection2->State));

// Open a connection using a DSN and OLE DB tags.
//TESTHR(pConnection3.CreateInstance(__uuidof(Connection)));
//pConnection3->ConnectionString = "Data Source=DataPubs;";
//pConnection3->Open("", "", "", adConnectUnspecified);
//printf("cnn3 state: %s\n", (LPCTSTR)GetState(pConnection3->State));

// Open a connection using a DSN and individual arguments instead of a connection string.
// It is assumed that you have create DSN 'DataPubs' with a user name as
// 'MyUserId' and password as 'MyPassword'.
//TESTHR(pConnection4.CreateInstance(__uuidof(Connection)));
//pConnection4->Open("DataPubs", "MyUserId", "MyPassword", adConnectUnspecified);
//printf("cnn4 state: %s\n", (LPCTSTR)GetState(pConnection4->State));
}
catch(_com_error &e) {
// Notify user of any errors. Pass a connection pointer accessed from the Connection.
PrintProviderError(pConnection1);
if (pConnection2)
PrintProviderError(pConnection2);

if (pConnection3)
PrintProviderError(pConnection3);

if (pConnection4)
PrintProviderError(pConnection4);

PrintComError(e);
}

// Cleanup objects before exit.
if (pConnection1)
if (pConnection1->State == adStateOpen)
pConnection1->Close();

if (pConnection2)
if (pConnection2->State == adStateOpen)
pConnection2->Close();

if (pConnection3)
if (pConnection3->State == adStateOpen)
pConnection3->Close();

if (pConnection4)
if (pConnection4->State == adStateOpen)
pConnection4->Close();
}

_bstr_t GetState(int intState) {
_bstr_t strState;
switch(intState) {
case adStateClosed:
strState = "adStateClosed";
break;
case adStateOpen:
strState = "adStateOpen";
break;
default:
;
}
return strState;
}

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);
}
AnswerRe: ADO Connection String. Pin
Rane20-Aug-09 18:12
Rane20-Aug-09 18:12 
AnswerRe: ADO Connection String. Pin
forexsurfr20-Aug-09 18:39
forexsurfr20-Aug-09 18:39 
GeneralRe: ADO Connection String. Pin
Rane21-Aug-09 0:55
Rane21-Aug-09 0:55 
QuestionHow can i do a unique reference to a function name that appear in two classes ? Pin
SNArruda20-Aug-09 13:40
SNArruda20-Aug-09 13:40 
AnswerRe: How can i do a unique reference to a function name that appear in two classes ? Pin
Chuck O'Toole20-Aug-09 15:13
Chuck O'Toole20-Aug-09 15:13 
GeneralRe: How can i do a unique reference to a function name that appear in two classes ? Pin
SNArruda20-Aug-09 16:49
SNArruda20-Aug-09 16:49 
GeneralRe: How can i do a unique reference to a function name that appear in two classes ? Pin
KarstenK20-Aug-09 21:33
mveKarstenK20-Aug-09 21:33 
GeneralRe: How can i do a unique reference to a function name that appear in two classes ? Pin
Stuart Dootson20-Aug-09 23:41
professionalStuart Dootson20-Aug-09 23:41 
QuestionSandCastle Help Builder with C++ Dynamic DLL (MFC) Pin
Member 437978320-Aug-09 11:22
Member 437978320-Aug-09 11:22 
AnswerRe: SandCastle Help Builder with C++ Dynamic DLL (MFC) Pin
Joe Woodbury20-Aug-09 17:43
professionalJoe Woodbury20-Aug-09 17:43 
GeneralRe: SandCastle Help Builder with C++ Dynamic DLL (MFC) Pin
Member 437978321-Aug-09 0:50
Member 437978321-Aug-09 0:50 
QuestionDefault type Pin
thelonesquirrely20-Aug-09 7:59
thelonesquirrely20-Aug-09 7:59 
AnswerRe: Default type Pin
Graham Shanks20-Aug-09 8:11
Graham Shanks20-Aug-09 8:11 
AnswerRe: Default type Pin
Maximilien20-Aug-09 8:19
Maximilien20-Aug-09 8:19 
GeneralRe: Default type Pin
thelonesquirrely20-Aug-09 8:22
thelonesquirrely20-Aug-09 8:22 
GeneralRe: Default type Pin
Maximilien20-Aug-09 9:08
Maximilien20-Aug-09 9:08 
QuestionDoxygen help Pin
Pabolo20-Aug-09 7:35
Pabolo20-Aug-09 7:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.