sql server语言 - 使用Microsoft OLE DB提供程序和sql Native OLE DB提供程序建立数据



我通过使用oledb提供程序(SQLOLEDB和SQL Native oledb提供程序)创建了一个示例应用程序。

案例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 = /*con_string*/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 establishedn");

结果:如果在服务器机器上安装了证书,那么无论启用与否,连接都是安全的Encrypt=true and TrustServerCertificate=true from in connection string.

案例2:Provider = SQLNCLI10.1(SQL本地客户端oledb Provider)

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/*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 suppliernumber, name1 FROM zrs_supplier";
BSTR query = sql.AllocSysString();
_RecordsetPtr rs;
rs = cADOConnection->Execute(query, &vaNoRecords, adCmdText);
printf("connection has been establishedn");

结果:如果在服务器机器上安装了证书,那么无论启用与否,连接都是安全的Encrypt=true and TrustServerCertificate=true from in connection string. i.e.结果与上面相同。

在这两种情况下,我得到相同的行为。我是不是错过了什么??任何建议都会很感激??最初的问题


将连接字符串替换为

CString SSlcon_string = "provider=SQLOLEDB;Use Encryption for Data=True;server=MYPC;Database=MyDB"; 

其余步骤相同。在客户端机器的"可信根证书颁发机构"文件夹中安装相同的证书(存在于服务器上)。

如果服务器和客户端都有相同的证书,那么连接将建立(SSL连接),否则将失败。

相关内容

  • 没有找到相关文章

最新更新