CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2005
    Posts
    221

    Question OLE DB ::Open parameters

    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:

    Code:
    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:

    Code:
    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:

    Code:
    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.

  2. #2
    Join Date
    Jun 2005
    Posts
    1,255

    Re: OLE DB ::Open parameters

    Do you know what kind of error do you get when it fails?

    With a CDBPropSet filled in the way you do, you can find the following examples: http://www.codeproject.com/database/oledbconsumer1.asp, http://www.codeproject.com/database/oledbconsumer1.asp, http://www.p2p.wrox.com/archive/visu...2002-01/57.asp.

    But I prefer the method where you give a connection string, with the DBPROP_INIT_PROVIDERSTRING property, like in the example at http://www.vchome.net/tech/document/...Procedures.htm

    You can find several examples of property strings at http://www.connectionstrings.com/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured