SQL SSMS 与 .Net 性能查询
SQL SSMS VS .Net Perfomance Query
我已经在我的电脑上安装了 Sql Server Management Studio。
然后我远程连接到我的一个数据库
我执行一个 returns 6000 条记录的查询几乎用了 1 或 2 秒
但 当我 运行 来自 .Net 应用程序(WPF 桌面)的相同查询也来自同一台 PC 时,数据传输几乎需要 8-9 秒
我在 .Net 中的代码非常简单明了
这是代码
Private Sub Button_Click(sender As Object, e As RoutedEventArgs)
Dim Sql_Connection As New SqlClient.SqlConnection("MyRemoteSQLConnectionString")
Dim Sql_Command As New SqlClient.SqlCommand("select Col1,Col2,Col3,Col4,Col5,Col6 from Table", Sql_Connection)
Sql_Connection.Open()
dr = Sql_Command.ExecuteReader
Dim DataTable As New DataTable
DataTable.Load(dr)
'The above code takes 8-9 seconds to finished but in ssmo takes only 1-2 seconds for 6000 Records
Sql_Connection.Close()
End Sub
为什么会这样? dose ssms 有不同的方式来管理传输的数据?
好的,
看来我在这个 POST
中找到了答案
Same query with the same query plan takes ~10x longer when executed from ADO.NET vs. SMSS
ado.net ConnectionString 中的 MultipleActiveResultsSet 选项应为 FALSE
和@DanGuzman 感谢您解决这个问题。 "SSMS also uses ADO.NET."
我已经在我的电脑上安装了 Sql Server Management Studio。
然后我远程连接到我的一个数据库
我执行一个 returns 6000 条记录的查询几乎用了 1 或 2 秒 但 当我 运行 来自 .Net 应用程序(WPF 桌面)的相同查询也来自同一台 PC 时,数据传输几乎需要 8-9 秒
我在 .Net 中的代码非常简单明了
这是代码
Private Sub Button_Click(sender As Object, e As RoutedEventArgs)
Dim Sql_Connection As New SqlClient.SqlConnection("MyRemoteSQLConnectionString")
Dim Sql_Command As New SqlClient.SqlCommand("select Col1,Col2,Col3,Col4,Col5,Col6 from Table", Sql_Connection)
Sql_Connection.Open()
dr = Sql_Command.ExecuteReader
Dim DataTable As New DataTable
DataTable.Load(dr)
'The above code takes 8-9 seconds to finished but in ssmo takes only 1-2 seconds for 6000 Records
Sql_Connection.Close()
End Sub
为什么会这样? dose ssms 有不同的方式来管理传输的数据?
好的, 看来我在这个 POST
中找到了答案Same query with the same query plan takes ~10x longer when executed from ADO.NET vs. SMSS
ado.net ConnectionString 中的 MultipleActiveResultsSet 选项应为 FALSE
和@DanGuzman 感谢您解决这个问题。 "SSMS also uses ADO.NET."