我想使用SSL连接到我的本地SQL Server 2008数据库。
我没有在服务器上安装任何证书,因为根据这个http://msdn.microsoft.com/en-us/library/ms189067.aspx
请注意,
我没有在服务器上安装任何证书,因为根据这个http://msdn.microsoft.com/en-us/library/ms189067.aspx
这是简单的代码。如果没有安装受信任的证书,SQL Server会在实例启动时生成自签名证书,并使用自签名证书加密凭据。
SqlConnection connection =
new SqlConnection(@"Data Source=somePC\SqlExpress;Initial Catalog=test;integrated security = sspi;Persist Security Info=True;Encrypt=true;");
SqlCommand command = new SqlCommand("Select count(*) from Employee", connection);
connection.Open();
int employeeCount = (int)command.ExecuteScalar();
connection.Close();`
请注意,
encrypt=true;
但是在connection.Open()
时会引发异常,异常信息如下:
我该如何批准这个自签名证书?已经成功与服务器建立连接,但在预登录握手期间发生错误。(提供程序: SSL提供程序,错误: 0 - 证书链由不受信任的授权机构颁发。)