Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. SQL Server CE : How to create a database from C++ with ADO

SQL Server CE : How to create a database from C++ with ADO

Scheduled Pinned Locked Moved Database
databasec++sql-serversysadminsecurity
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Leif Goodwin
    wrote on last edited by
    #1

    I have a demo application that uses SQL Server via ADO to create and populate a database. I connect to the master database and then execute a "CREATE DATABASE ..." SQL statement. Here is the connect: bool CMsSqlDemoView::Connect(LPCTSTR szDatabase) { Disconnect(); m_DBConnection.CreateInstance(__uuidof(Connection)); if (!m_DBConnection) { m_listErrors.AddString("Failed to create ADO::Connection instance"); return(false); } m_DBConnection->CursorLocation = adUseClient; // Note: The "sqloledb" provider does not fully support XML. // For XML support, the Provider and DataTypeCompatibility values must be set as indicated. CString strConnection; strConnection.Format( "Provider=SQLNCLI10;DataTypeCompatibility=80;Integrated Security=SSPI;Data Source=%s;Database=%s;Trusted_Connection=Yes;", m_strDataSource.GetString(), szDatabase); HRESULT hr = E_FAIL; bool bResult = true; try { hr = m_DBConnection->Open(strConnection.GetString(), "", "", adConnectUnspecified); } catch(_com_error &e) { CString strText; strText.Format("Error code '%d' : '%s'", e.Error(), (LPCTSTR)e.Description()); m_listErrors.AddString(strText); bResult = false; } return(bResult); } So far so good. I have now created a second demo application that uses SQL Server CE 3.5. I set the provider as "Microsoft.SQLSERVER.CE.OLEDB.3.5" but I am unable to create a connection object, and I have no idea how to create a database since I cannot connect to a master database. Anyone know how to do this (C++)? Thanks. BY the way I don't want to use managed C++, or OLEDB.

    modified on Tuesday, October 26, 2010 8:52 AM

    L 1 Reply Last reply
    0
    • L Leif Goodwin

      I have a demo application that uses SQL Server via ADO to create and populate a database. I connect to the master database and then execute a "CREATE DATABASE ..." SQL statement. Here is the connect: bool CMsSqlDemoView::Connect(LPCTSTR szDatabase) { Disconnect(); m_DBConnection.CreateInstance(__uuidof(Connection)); if (!m_DBConnection) { m_listErrors.AddString("Failed to create ADO::Connection instance"); return(false); } m_DBConnection->CursorLocation = adUseClient; // Note: The "sqloledb" provider does not fully support XML. // For XML support, the Provider and DataTypeCompatibility values must be set as indicated. CString strConnection; strConnection.Format( "Provider=SQLNCLI10;DataTypeCompatibility=80;Integrated Security=SSPI;Data Source=%s;Database=%s;Trusted_Connection=Yes;", m_strDataSource.GetString(), szDatabase); HRESULT hr = E_FAIL; bool bResult = true; try { hr = m_DBConnection->Open(strConnection.GetString(), "", "", adConnectUnspecified); } catch(_com_error &e) { CString strText; strText.Format("Error code '%d' : '%s'", e.Error(), (LPCTSTR)e.Description()); m_listErrors.AddString(strText); bResult = false; } return(bResult); } So far so good. I have now created a second demo application that uses SQL Server CE 3.5. I set the provider as "Microsoft.SQLSERVER.CE.OLEDB.3.5" but I am unable to create a connection object, and I have no idea how to create a database since I cannot connect to a master database. Anyone know how to do this (C++)? Thanks. BY the way I don't want to use managed C++, or OLEDB.

      modified on Tuesday, October 26, 2010 8:52 AM

      L Offline
      L Offline
      Leif Goodwin
      wrote on last edited by
      #2

      In case anyone else needs the answer, I had to use the MS_ADOX::_Catalog COM interface which is imported from msadox.dll. For example: MS_ADOX::_CatalogPtr catalogPtr; catalogPtr.CreateInstance(__uuidof(MS_ADOX::Catalog)); catalogPtr->Create("Provider=Microsoft.SQLSERVER.CE.OLEDB.3.5;Data Source=C:\\Temp\\sqlcedemo.sdf;"); The above crap non error checking code creates the C:\\Temp\\sqlcedemo.sdf database, which can then be opened and populated using ADO in the normal fashion.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups