SQL Server 2016始终在已发布的IIS上加密超时 [英] SQL Server 2016 Always Encrypted Timeout at Published IIS

查看:340
本文介绍了SQL Server 2016始终在已发布的IIS上加密超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试将我的asp.net mvc应用程序发布到我的本地(pc)iis并启用始终加密时,我遇到了一些奇怪的问题。

I Have strange problem when i tried to publish my asp.net mvc application to my local (pc) iis with "Always Encrypted" Enabled.

当我尝试在本地IIS(不是快递)使用EF6访问数据库时,我的应用程序保持超时:

My application keep timeout when i tried to access database using EF6 at local IIS (not express) :

但如果我试过访问&使用Visual Studio 2017调试我的asp.net mvc应用程序,可以完美地访问始终加密已启用的数据库而不会超时。

But if i tried to access & debug my asp.net mvc app using Visual Studio 2017, database with 'always encrypted enabled' can be accessed perfectly without timeout.

我还可以使用SQL Management Studio轻松访问它。

And also i can access it with SQL Management Studio without problem.

使用此配置的两者(SMSS和ASP.NET网络配置)。

Both (SMSS & ASP.NET web config) using this configuration.

Column Encryption Setting=enabled;

注意:我正在使用ASP.NET MVC 5& EF 6,SQL Server 2016开发人员版。

Note : I'm using ASP.NET MVC 5 & EF 6, SQL Server 2016 Developer Edition.

对不起,我的英文不好。

Sorry for my bad english.

更新:
我尝试过使用.NET Framework数据提供程序查看是否有任何线索可以帮助我解决此问题,使用以下代码:

UPDATED : I have tried using .NET Framework Data Provider to see if there's any clue that'll help me solving this issue, Using following code :

var context = new TestDevEntities();
            StringBuilder sb = new StringBuilder();
            string connectionString = context.Database.Connection.ConnectionString;
            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                connection.Open();
                using (SqlCommand cmd = new SqlCommand(@"SELECT [id],[name],[CCno]  FROM [TestDev].[dbo].[testEncCol]", connection, null, SqlCommandColumnEncryptionSetting.ResultSetOnly))
                {
                    using (SqlDataReader reader = cmd.ExecuteReader())
                    {
                        if (reader.HasRows)
                        {
                            
                            while (reader.Read())
                            {
                                sb.Append(reader[2] + ";");
                            }
                        }
                    }
                }
            }

以上代码显示此错误:

above code show me this error :

现在,有了这种错误,我知道我必须这样做:)

Now, with this kind of error i know i exactly i must do :)


  1. 将应用程序池的身份更改为之前生成的用户证书。

  2. 导出currentuser cert(由始终加密使用)并导入到要用作应用程序池标识的用户。

现在工作了!

EF应该像.NET数据提供商一样清楚地发出某种错误,而不是超时失败真的很迷惑我@ _ @

EF should throw some kind of error as clear as .NET Data Providers do, instead of timeout failure that really confuse me @_@

更新(1):
现在问题是如何使用它(证书)与德错误ApplicationPoolIdentity而不是自定义帐户?

UPDATED (1) : Now the question is how to use it (Certificate) with default ApplicationPoolIdentity instead of custom account?

更新(2):
我做了什么 jakub 建议,但仍然没有运气。

UPDATED (2) : I have done what jakub suggest, but still no luck.

谢谢

推荐答案

使用DefaultAppPool标识而不是自定义的一种方式(可能是唯一的方法) (用户)帐户是将证书存储在本地计算机证书存储区(而非当前用户)中。

One way (could be the only way) to use the DefaultAppPool identity instead of a custom (user) account is to store the certificate in the Local Machine certificate store (not Current User).

在本地计算机证书存储中创建证书后,您需要授予DefaultAppPool对证书的访问权限。您可以使用Microsoft管理控制台(以及本地计算机证书插件)执行此操作:

Once you create a certificate in the Local Machine certificate store, you need to grant DefaultAppPool access to the cert. You can do that using Microsoft Management Console (and the plugin for Local Computer certs):


  1. 右键单击证书,选择所有任务>管理私钥。

  2. 单击添加。

  3. 为您的计算机(而非您的域)设置位置。

  4. 输入IIS AppPool \DefaultAppPool作为对象名称。

  5. 单击确定两次。

  1. Right click on the cert, select All Tasks > Manage Private Keys.
  2. Click Add.
  3. Set location to your computer (not your domain).
  4. Enter IIS AppPool\DefaultAppPool as the object name.
  5. Click OK twice.

这篇关于SQL Server 2016始终在已发布的IIS上加密超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆