我想使用SSL連接到本地SQL Server 2008數據庫。SSL連接到SQL Server時出現問題
我沒有,因爲根據該http://msdn.microsoft.com/en-us/library/ms189067.aspx
If a trusted certificate is not installed, SQL Server will generate a self-signed certificate when the instance is started, and use the self-signed certificate to encrypt the credentials.
在服務器上安裝任何證書,這是簡單的代碼
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()
的例外是用訊息舉報
A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: SSL Provider, error: 0 - The certificate chain was issued by an authority that is not trusted.)
我可以批准這個自簽名證書嗎?
實際上並非如此。 SQL Server將在實例啓動時生成一個自簽名證書 – Disappointed