1
Reply

Connecting to Northwind

Raymond Flach

Raymond Flach

Jan 16 2006 9:50 PM
2.2k
I am learning to program C++ .net and am having difficulty with one of the exercises and wondered if someone could help? I am including the code for a console app I wrote according to the exercise that is supposed to create a connection to the Northwind.mdb database. I modified the code for the ConnectionString to include the path to where I found Northwind.mdb to be located on my machine. When I run the program, I get the following error: An unhandled exception of type 'System.InvalidOperationException' occurred in system.data.dll Additional information: The 'Microsoft.Jet.OLEDB.4.0: Data Source=C:\Program Files\Microsoft Office\Office\Samples\northwind.mdb' provider is not registered on the local machine. Can anyone help me? // This is the main project file for VC++ application project // generated using an Application Wizard. #include "stdafx.h" #using using namespace System; //Generic ADO.NET definitions using namespace System::Data; //specific Oledb provider definitions using namespace System::Data::OleDb; int _tmain() { //create a connection OleDbConnection* cnNwind = new OleDbConnection(); //Set the connection string cnNwind->ConnectionString = S" Provider=Microsoft.Jet.OLEDB.4.0: " S"Data Source=C:\\Program Files\\Microsoft Office\\Office\\Samples\\northwind.mdb"; try { //Open the database cnNwind->Open(); Console::WriteLine(S"Connected to database successfully!"); } catch(OleDbException* pe) { Console::Write(S"Error occurred: "); Console::WriteLine(pe->Message); } //Close the connection if (cnNwind->State != ConnectionState::Closed) { cnNwind->Close(); } Console::WriteLine(S"The database connection is now closed"); return 0; }

Answers (1)