2011-08-11 11 views
2

SSLを使用してローカルのSQL Server 2008データベースに接続したいとします。SQL ServerへのSSL接続中の問題

この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.)

この自己署名証明書を承認することはできますか?

答えて

2

In order for RPC over Http to work you must have a Trusted CA Root Certificate installed and configured. In a situation where you are using a self-signed cert you will need to install the certificate into the Trusted Root Certification Authorities store.

Install the cert into your trusted root store.

+0

実際にはありません。 SQL Serverは、インスタンスの起動時に自己署名証明書を生成します – Disappointed

6

あなたは提示されているものの証明書を信頼するようにクライアントを指示する必要があります。自己署名証明書は、コンピュータが信頼するCAによって署名されていないため、信頼されません。次のようにTrustServerCertificate = Trueを追加して接続を変更します。

SqlConnection connection = 
    new SqlConnection(@"Data Source=somePC\SqlExpress;Initial Catalog=test;integrated security = sspi;Persist Security Info=True;Encrypt=true; TrustServerCertificate=True"); 

SqlCommand command = new SqlCommand("Select count(*) from Employee", connection); 
connection.Open(); 
int employeeCount = (int)command.ExecuteScalar(); 
connection.Close(); 
関連する問題