gpt4 book ai didi

c# - SQL Server 2008 R2 上的身份验证设置是否会对性能产生影响?

转载 作者:可可西里 更新时间:2023-11-01 08:47:56 24 4
gpt4 key购买 nike

好的这是第一种方法

public static string srConnectionString = "server=localhost;database=myDB; "+
" uid=sa;pwd=myPW;";

这是第二种方法

public static string srConnectionString = "server=localhost;database=myDB; "+
" integrated security=SSPI;persist security info=False; Trusted_Connection=Yes;";

这两个连接字符串之间是否存在任何性能差异或任何其他差异?

这里我的 sql 连接类有什么建议吗?

using System;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Data;

public static class DbConnection

{
public static string srConnectionString = "server=localhost; database=myDB; uid=sa; pwd=myPW;";

public static DataSet db_Select_Query(string strQuery)
{
DataSet dSet = new DataSet();
if (strQuery.Length < 5)
return dSet;
try
{
using (SqlConnection connection = new SqlConnection(srConnectionString))
{
connection.Open();
using (SqlDataAdapter DA = new SqlDataAdapter(strQuery, connection))
{
DA.Fill(dSet);
}
}
return dSet;
}
catch
{
using (SqlConnection connection = new SqlConnection(srConnectionString))
{
if (srConnectionString.IndexOf("select Id from tblAspErrors") != -1)
{
connection.Open();
strQuery = strQuery.Replace("'", "''");

using (SqlCommand command = new SqlCommand("insert into tblSqlErrors values ('" + strQuery + "')", connection))
{
command.ExecuteNonQuery();
}
}
}
return dSet;
}
}

public static void db_Update_Delete_Query(string strQuery)
{
if (strQuery.Length < 5)
return;
try
{
using (SqlConnection connection = new SqlConnection(srConnectionString))
{
connection.Open();
using (SqlCommand command = new SqlCommand(strQuery, connection))
{
command.ExecuteNonQuery();
}
}
}
catch
{
strQuery = strQuery.Replace("'", "''");
using (SqlConnection connection = new SqlConnection(srConnectionString))
{
connection.Open();
using (SqlCommand command = new SqlCommand("insert into tblSqlErrors values ('" + strQuery + "')", connection))
{
command.ExecuteNonQuery();
}
}
}
}

最佳答案

性能差异可以忽略不计。身份验证检查是

  1. ...仅在登录时执行。不会为每个查询重新检查连接。然而,对于连接池,连接会被多次验证和重置,很可能对于几乎每个查询都是如此
  2. ...与针对 Active Directory 检查域的每个文件访问和其他事件相同

仅供引用,这两个设置是相同的(使用一个或另一个):

integrated security=SSPI
Trusted_Connection=Yes

关于c# - SQL Server 2008 R2 上的身份验证设置是否会对性能产生影响?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13959707/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com