了解 ASP.NET ConnectionPool 和字符串安全
Understanding ASP.NET ConnectionPool and string security
我正在 ASP.NET 中编写一个应用程序,我在那里经常进行 SQL 连接,我所说的频繁是指每 2 秒一次。它是实时数据应用程序。
BD引擎是SQL服务器2008R2。
每个用户至少连接到两个不同的数据库。
我的问题是我仍然无法理解连接池以及经过一些查询后我将拥有多少连接。
我实现了以下方法:
private static string composeConnectionString(string connectTo)
{
StringBuilder sqlSB = new StringBuilder("Data Source=");
sqlSB.Append(dataSource);
sqlSB.Append(";Min Pool Size=");
sqlSB.Append(minPoolSize);
sqlSB.Append(";Max Pool Size=");
sqlSB.Append(maxPoolSize);
sqlSB.Append(";Connection Timeout=");
sqlSB.Append(connectionTimeout);
sqlSB.Append(";Initial Catalog=");
sqlSB.Append(connectTo);
sqlSB.Append(";Integrated Security=");
sqlSB.Append(integratesSecurity);
sqlSB.Append(";User Id=");
sqlSB.Append(userId);
sqlSB.Append(";Password=");
sqlSB.Append(password);
sqlSB.Append(";MultipleActiveResultSets=");
sqlSB.Append(multipleActiveResultSets);
return sqlSB.ToString();
}
public static SqlConnection getConnection(string connectTo)
{
SqlConnection connection = null;
string connectionString = composeConnectionString(connectTo);
try
{
connection = new SqlConnection(connectionString);
}
catch (Exception ex)
{
if (connection != null)
connection = null;
ExceptionLogger.LogException(ex, connectionString);
}
return connection;
}
在这一点上,我开始质疑新的 ConnectionPool 是否是我寻找的每个 SQLConnection 的创建者?
连接字符串的安全性如何?
如果有些内容看起来模糊,请向我询问更新。
谢谢大家
- 取决于您的配置。如果您为池配置至少一个连接,最多 3 个连接,当您的第一个连接发生时,如果启用了池,连接将检查至少 1 个和最多 3 个连接。
The pooler maintains ownership of the physical connection. It manages
connections by keeping alive a set of active connections for each
given connection configuration. Whenever a user calls Open on a
connection, the pooler looks for an available connection in the pool.
If a pooled connection is available, it returns it to the caller
instead of opening a new connection. When the application calls Close
on the connection, the pooler returns it to the pooled set of active
connections instead of closing it. Once the connection is returned to
the pool, it is ready to be reused on the next Open call.
您可以在此处阅读更多内容:https://msdn.microsoft.com/en-us/library/8xx3tyca%28v=vs.110%29.aspx
- 关于连接字符串,如果您使用用户名和密码作为凭据,则存在安全问题。您可以使用 Windows 身份验证来确保您的连接字符串没有任何敏感数据,或者,如果您使用的是 IIS,您可以将连接字符串存储在其中以保护您的数据。
在此处阅读有关连接字符串的更多信息:https://msdn.microsoft.com/pt-br/library/system.data.sqlclient.sqlconnection.connectionstring%28v=vs.110%29.aspx
关于在这里保护连接字符串:https://msdn.microsoft.com/en-us/library/89211k9b%28v=vs.110%29.aspx
希望对您有所帮助。
我正在 ASP.NET 中编写一个应用程序,我在那里经常进行 SQL 连接,我所说的频繁是指每 2 秒一次。它是实时数据应用程序。 BD引擎是SQL服务器2008R2。
每个用户至少连接到两个不同的数据库。 我的问题是我仍然无法理解连接池以及经过一些查询后我将拥有多少连接。
我实现了以下方法:
private static string composeConnectionString(string connectTo)
{
StringBuilder sqlSB = new StringBuilder("Data Source=");
sqlSB.Append(dataSource);
sqlSB.Append(";Min Pool Size=");
sqlSB.Append(minPoolSize);
sqlSB.Append(";Max Pool Size=");
sqlSB.Append(maxPoolSize);
sqlSB.Append(";Connection Timeout=");
sqlSB.Append(connectionTimeout);
sqlSB.Append(";Initial Catalog=");
sqlSB.Append(connectTo);
sqlSB.Append(";Integrated Security=");
sqlSB.Append(integratesSecurity);
sqlSB.Append(";User Id=");
sqlSB.Append(userId);
sqlSB.Append(";Password=");
sqlSB.Append(password);
sqlSB.Append(";MultipleActiveResultSets=");
sqlSB.Append(multipleActiveResultSets);
return sqlSB.ToString();
}
public static SqlConnection getConnection(string connectTo)
{
SqlConnection connection = null;
string connectionString = composeConnectionString(connectTo);
try
{
connection = new SqlConnection(connectionString);
}
catch (Exception ex)
{
if (connection != null)
connection = null;
ExceptionLogger.LogException(ex, connectionString);
}
return connection;
}
在这一点上,我开始质疑新的 ConnectionPool 是否是我寻找的每个 SQLConnection 的创建者? 连接字符串的安全性如何?
如果有些内容看起来模糊,请向我询问更新。
谢谢大家
- 取决于您的配置。如果您为池配置至少一个连接,最多 3 个连接,当您的第一个连接发生时,如果启用了池,连接将检查至少 1 个和最多 3 个连接。
The pooler maintains ownership of the physical connection. It manages connections by keeping alive a set of active connections for each given connection configuration. Whenever a user calls Open on a connection, the pooler looks for an available connection in the pool. If a pooled connection is available, it returns it to the caller instead of opening a new connection. When the application calls Close on the connection, the pooler returns it to the pooled set of active connections instead of closing it. Once the connection is returned to the pool, it is ready to be reused on the next Open call.
您可以在此处阅读更多内容:https://msdn.microsoft.com/en-us/library/8xx3tyca%28v=vs.110%29.aspx
- 关于连接字符串,如果您使用用户名和密码作为凭据,则存在安全问题。您可以使用 Windows 身份验证来确保您的连接字符串没有任何敏感数据,或者,如果您使用的是 IIS,您可以将连接字符串存储在其中以保护您的数据。
在此处阅读有关连接字符串的更多信息:https://msdn.microsoft.com/pt-br/library/system.data.sqlclient.sqlconnection.connectionstring%28v=vs.110%29.aspx
关于在这里保护连接字符串:https://msdn.microsoft.com/en-us/library/89211k9b%28v=vs.110%29.aspx
希望对您有所帮助。