I created an example application using both the oledb provider (SQLOLEDB and the NED OLEDB SQL provider).
Case 1: Provider = SQLOLEDB
hr = ::CoInitializeEx(NULL, COINIT_MULTITHREADED); hr = cADOConnection.CreateInstance(__uuidof(Connection)); CString con_string = "provider=SQLOLEDB;server=MYPC;Database=MyDB"; CString SSlcon_string = "provider=SQLOLEDB;Encrypt=true;TrustServerCertificate=true;server=MYPC;Database=MyDB"; CString userName = "sa"; CString Password = "sa"; BSTR bsConnection = SSlcon_string.AllocSysString(); BSTR uName = userName.AllocSysString(); BSTR uPassword = Password.AllocSysString(); hr = cADOConnection->Open(bsConnection, uName, uPassword, adConnectUnspecified); printf("connection has been established"); VARIANT vaNoRecords; memset(&vaNoRecords, 0, sizeof vaNoRecords); CString sql = "SELECT * FROM salary"; BSTR query = sql.AllocSysString(); _RecordsetPtr rs; rs = cADOConnection->Execute(query, &vaNoRecords, adCmdText); printf("connection has been established\n");
Result: if the certificate is installed on the server, then the connection is protected regardless of the inclusion of Encrypt = true and TrustServerCertificate = true from the connection string.
Case 2: Provider = SQLNCLI10.1 (Client Provider for Local SQL Client)
HRESULT hr; hr = ::CoInitializeEx(NULL, COINIT_MULTITHREADED); hr = cADOConnection.CreateInstance(__uuidof(Connection)); CString con_string = "provider=SQLNCLI10.1;server=MYPC;Database=MyDB"; CString SSlcon_string = "provider=SQLOLEDB;Encrypt=true;TrustServerCertificate=true;server=MYPC;Database=MyDB"; CString userName = "sa"; CString Password = "sa"; BSTR bsConnection = con_string.AllocSysString(); BSTR uName = userName.AllocSysString(); BSTR uPassword = Password.AllocSysString(); hr = cADOConnection->Open(bsConnection, uName, uPassword, adConnectUnspecified); printf("connection has been established"); VARIANT vaNoRecords; memset(&vaNoRecords, 0, sizeof vaNoRecords); CString sql = "SELECT suppliernumber, name1 FROM zrs_supplier"; BSTR query = sql.AllocSysString(); _RecordsetPtr rs; rs = cADOConnection->Execute(query, &vaNoRecords, adCmdText); printf("connection has been established\n");
Result: if the certificate is installed on the server, the connection is protected regardless of the inclusion of Encrypt = true and TrustServerCertificate = true from in the string.ie connection. The result is the same as above.
In both cases, I get the same behavior. Am I missing something here? Any suggestion would be appreciated ?? Original question