none
SQL Connection fails SUA test with elevate off

    Question

  •  

    Is it possible to connect successfuly to Sql Server 2000 or 2005 on a non-Vista server from a Vista machine without using Ado.Net?

    Our application uses non-managed C++ code for database access. DotNet is not an option at this time. We've tried using test programs that only create a connection object and attempt to open the connection with the same results as testing our application.

    Using the SUA test, the connection succeeds when elevated and fails when not elevated with a null pointer exception. The application verifier log file shows numerous registry errors on successful connection. I don't know if the errors are actually related to the failure sinch no entries show on failure.

    Running a simular test with managed C++ code and ADO.NET to make the connection is successful for both elevated or not elevated.

    Tests have been made using OLEDB and SQLOLEDB.

    Any ideas or thoughts are appreciated.

     

     

    Wednesday, March 21, 2007 6:38 PM

Answers

  • I could not get any of the various connections to work on Vista with out elevation except for ADO.NET. Using simple test programs simular to the one below, I attempted to create a connection using various providers and connection types. The results were the same, the connection was successful when elevate was allowed and failed with a null pointer exception if elevate was not allowed. The null pointer is the connection object which does not create if not elevated.

     

    We were able to convert our application to use ADO.NET for the connection to get past this issue. It does seem other methods of connectivity would be possible. 

    Code Snippet

    void DbConnect()
    {
     try {
      HRESULT hr;

    _ConnectionPtr pConn;
      hr = pConn.CreateInstance(__uuidof(Connection));
      _bstr_t strConn("Provider=sqloledb;Data Source=<server>;Initial Catalog=<database>;");
      hr = pConn->Open(strConn, "user", "*****", adConnectUnspecified);

    if( hr == S_OK){
        MessageBox(NULL, _T("Connected"), _T("Test Result"), MB_OK);
      }
      else{
        MessageBox(NULL, _T("Connection failed."), _T("Test Result"), MB_OK);
      }

    hr = pConn->Close(); 
     }
     catch(_com_error &e) {
        MessageBox(NULL, e.ErrorMessage(), _T("Test Result"), MB_OK);


    }

     

     

    Wednesday, March 28, 2007 1:00 PM

All replies

  • The following should be valid: SQL Server using SQL Native Client, OLEDB, ODBC, ADO, MDAC JDBC, or SOAP/HTTP. For .NET (ADO.NET) use Data Access Forum in the .NET group.

    Check the MSDN SQL area for more detailed information on SQL connectivity.

    Wednesday, March 21, 2007 8:05 PM
  • I could not get any of the various connections to work on Vista with out elevation except for ADO.NET. Using simple test programs simular to the one below, I attempted to create a connection using various providers and connection types. The results were the same, the connection was successful when elevate was allowed and failed with a null pointer exception if elevate was not allowed. The null pointer is the connection object which does not create if not elevated.

     

    We were able to convert our application to use ADO.NET for the connection to get past this issue. It does seem other methods of connectivity would be possible. 

    Code Snippet

    void DbConnect()
    {
     try {
      HRESULT hr;

    _ConnectionPtr pConn;
      hr = pConn.CreateInstance(__uuidof(Connection));
      _bstr_t strConn("Provider=sqloledb;Data Source=<server>;Initial Catalog=<database>;");
      hr = pConn->Open(strConn, "user", "*****", adConnectUnspecified);

    if( hr == S_OK){
        MessageBox(NULL, _T("Connected"), _T("Test Result"), MB_OK);
      }
      else{
        MessageBox(NULL, _T("Connection failed."), _T("Test Result"), MB_OK);
      }

    hr = pConn->Close(); 
     }
     catch(_com_error &e) {
        MessageBox(NULL, e.ErrorMessage(), _T("Test Result"), MB_OK);


    }

     

     

    Wednesday, March 28, 2007 1:00 PM