RogerGarrett
July 25th, 2005, 05:26 PM
I'm having difficulty figuring out how to set up the parameters for doing an Open with the CDataSource class.
My database is named "MyDatabase".
It's an OLE DB type of database.
The Provider is Microsoft OLE DB Provider for SQL Server, so I think that means using the string "SQLOLEDB" as a parameter to the Open method.
My Server Name is "MyServer".
I can successully open it up using just:
CDataSource theDatabase;
hResult = theDatabase.Open();
which simply prompts me via a dialog for all the various information.
But I need to do it programmatically.
I think I need to set up a CDBPropSet with something like:
CDBPropSet dbPropertySet(DBPROPSET_DBINIT);
dbPropertySet.AddProperty(DBPROP_AUTH_PERSIST_SENSITIVE_AUTHINFO, false);
dbPropertySet.AddProperty(DBPROP_INIT_DATASOURCE, "RogesPlaceOLEDB");
dbPropertySet.AddProperty(DBPROP_INIT_PROMPT, (short)DBPROMPT_NOPROMPT);
dbPropertySet.AddProperty(DBPROP_INIT_LCID, (long)2057); // NOTE: this came from page 159 of the Visual C++ 6 DATABASE PROGRAMMING TUTORIAL book
and then open it with something like:
HRESULT hResult;
hResult = m_Database.Open(_T("SQLOLEDB"),&dbPropertySet);
but it always fails.
I'm obviously not passing in the name of the server (i.e. "MyServer") anywhere, but I can't figure out where to do that. And I suspect that some of the rest is also not quite right.
Any help would be greatly appreciated.
My database is named "MyDatabase".
It's an OLE DB type of database.
The Provider is Microsoft OLE DB Provider for SQL Server, so I think that means using the string "SQLOLEDB" as a parameter to the Open method.
My Server Name is "MyServer".
I can successully open it up using just:
CDataSource theDatabase;
hResult = theDatabase.Open();
which simply prompts me via a dialog for all the various information.
But I need to do it programmatically.
I think I need to set up a CDBPropSet with something like:
CDBPropSet dbPropertySet(DBPROPSET_DBINIT);
dbPropertySet.AddProperty(DBPROP_AUTH_PERSIST_SENSITIVE_AUTHINFO, false);
dbPropertySet.AddProperty(DBPROP_INIT_DATASOURCE, "RogesPlaceOLEDB");
dbPropertySet.AddProperty(DBPROP_INIT_PROMPT, (short)DBPROMPT_NOPROMPT);
dbPropertySet.AddProperty(DBPROP_INIT_LCID, (long)2057); // NOTE: this came from page 159 of the Visual C++ 6 DATABASE PROGRAMMING TUTORIAL book
and then open it with something like:
HRESULT hResult;
hResult = m_Database.Open(_T("SQLOLEDB"),&dbPropertySet);
but it always fails.
I'm obviously not passing in the name of the server (i.e. "MyServer") anywhere, but I can't figure out where to do that. And I suspect that some of the rest is also not quite right.
Any help would be greatly appreciated.