SQL Server连接中的时间延迟 [英] Time lag in SQL server connection
问题描述
我正在尝试从C#连接到远程SQL Server。每次打开连接时,打开连接至少需要6到10秒,并在打开连接后执行步骤。
例如
I am trying to connect to a remote SQL Server from C#. Each time when I open connection, it takes at least 6 to 10 seconds to open the connection and execute the steps after opening the conection.
e.g.
public static bool connectDB()
{
try
{
Variables var = new Variables();
string connection = Properties.Settings.Default.serverUrl;
var.connection = new SqlConnection(connection);
var.connection.Open(); //takes time to execute this step
{
//set of commands executes after time lag;
}
var.connection.Close();
return true;
}
catch (Exception ex)
{
MessageBox.Show("Error while conneting to database" + ex.Message,"Demo",MessageBoxButtons.OK,MessageBoxIcon.Error);
return false;
throw;
}
}
之后几分钟它运行顺利。几分钟后,打开一个连接需要6到10秒。
我尝试了什么:
我使用它作为连接字符串:
After that for few minutes it runs smoothly. Again after few minutes, it takes 6 to 10 seconds to open a connection.
What I have tried:
I am using this as a connection string:
Data Source=159.70.76.16;Initial Catalog=Itemsense;Integrated Security=True; max pool size=1000
我甚至试过从连接字符串中删除'max pool size'参数但是仍然有相同的时间滞后。有没有解决这个问题的方法?
I even tried by removing the 'max pool size' parameter from connection string but still getting same time lag. Is there any solution for this issue?
推荐答案
直接回答你的问题是不可能的原因......
1. a href =https://docs.microsoft.com/en-us/sql/sql-server/install/configure-the-windows-firewall-to-allow-sql-server-access> Windows防火墙不允许/锁定连接到SQL服务器 [ ^ ]
2. 局域网/广域网连接问题 [ ^ ]
3. SQL服务器性能问题
- SQL Server性能调优技巧 [ ^ ]
- SQL Server性能调优 [ ^ ]
4. etc.
不幸的是,你必须检查每种可能性。
祝你好运!
It's impossible to answer your question directly for set ot reason...
1. Windows firewall disallows/locks connection to SQL server[^]
2. LAN/WAN connection issues[^]
3. SQL server performance issues
- SQL Server Performance Tuning Tips[^]
- Performance Tuning for SQL Server[^]
4. etc.
Unfortunately, you have to check every possibility.
Good luck!
这篇关于SQL Server连接中的时间延迟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!